setClassToggle() 不适用于 DOM 对象作为参数,仅当给定参数是字符串时才有效:
// add the class 'myclass' to the element with the id 'my-elem' for the duration of the scene
scene.setClassToggle("#my-elem", "myclass"); // will work
scene.setClassToggle($("#my-elem"), "myclass"); // won't work
ScrollMagic 文档说它应该可以工作:
setClassToggle(element, classes) → {Scene}
element string | object
A Selector targeting one or more elements or a DOM object that is supposed to be modified.
请您参考如下方法:
您没有向其传递 DOM 对象,而是传递 JQuery 对象。尝试在该选择器末尾添加 [0]
并查看它是否有效。
scene.setClassToggle($("#my-elem")[0], "myclass");