Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

javascript - Call a function when window is resized inside a shopify theme

I'm trying to make some customization in a Shopify theme (the Brooklyn one). In this theme, there is a file theme.js.liquid in which they define a very large function slate.Variants(). Within this function, I defined another function filterSlidesOnMobile(variant) and call it within the large function slate.Variants().

I want to call my function filterSlidesOnMobile(variant) every time the windows resize. I tried to use jquery functions like resize() and onresize() within and out of slate.Variants() but no sucess. The problem is my function has a parameter variant which is defined in slate.Variants(), so it's obvious that calling the resize out of it won't work, but even when calling the resize within it, there is syntax errors like when I do $(window).resize(this.filterSlidesOnMobile(variant));, I get:

Uncaught SyntaxError: Unexpected token '.'

Where should I call the resize and how?

I precise that I'm new to Js and that any help will be greatly appreciated.

EDIT: As requested, here is a pastebin link to the function slate.Variants() in which I did all my work. Look up for lines 27 - 114 - 127 and 156. (This is what I added: except those lines, the theme file didn't change).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...