我试图在我的一个cutsom页面模板中加入视差效果。js函数在firebug控制台中返回以下错误:
TypeError: $ is not a function
错误出现在第一行,即:
var parallaxElements = $(\'.parallax\'),
任何帮助都将不胜感激。以下是完整代码:
var parallaxElements = $(\'.parallax\'),
parallaxQuantity = parallaxElements.length;
$(window).on(\'scroll\', function () {
window.requestAnimationFrame(function () {
for (var i = 0; i < parallaxQuantity; i++) {
var currentElement = parallaxElements.eq(i);
var scrolled = $(window).scrollTop();
currentElement.css({
\'transform\': \'translate3d(0,\' + scrolled * -0.3 + \'px, 0)\'
});
}
});
});