Jquery代码未执行
Jquery code is not executing
我目前正在学习jQuery。我对以下代码有一些问题。我试图用一些按钮让我的网站移动,但一旦我点击它们,它似乎就不起作用了。下面是我的jquery代码。
jQuery(document).ready(function ($) {
//initialise Stellar.js
$(window).stellar();
//Cache some variables
var links = $('.navigation').find('li');
slide = $('.slide');
button = $('.button');
mywindow = $(window);
htmlbody = $('html,body');
//Setup waypoints plugin
slide.waypoint(function (event, direction) {
//cache the variable of the data-slide attribute associated with each slide
dataslide = $(this).attr('data-slide');
//If the user scrolls up change the navigation link that has the same data-slide attribute as the slide to active and
//remove the active class from the previous navigation link
if(direction === 'down') {
$('.navigation li[data-slide="' + dataslide + '"]').addClass('active').prev().removeClass('active');
}
// else If the user scrolls down change the navigation link that has the same data-slide attribute as the slide to active and
//remove the active class from the next navigation link
else {
$('.navigation li[data-slide="' + dataslide + '"]').addClass('active').next().removeClass('active');
}
});
//waypoints doesnt detect the first slide when user scrolls back up to the top so we add this little bit of code, that removes the class
//from navigation link slide 2 and adds it to navigation link slide 1.
mywindow.scroll(function () {
if(mywindow.scrollTop() === 0) {
$('.navigation li[data-slide="1"]').addClass('active');
$('.navigation li[data-slide="2"]').removeClass('active');
}
});
//Create a function that will be passed a slide number and then will scroll to that slide using jquerys animate. The Jquery
//easing plugin is also used, so we passed in the easing method of 'easeInOutQuint' which is available throught the plugin.
function goToByScroll(dataslide) {
htmlbody.animate({
scrollTop: $('.slide[data-slide="' + dataslide + '"]').offset().top
}, 2000, 'easeInOutQuint');
}
//When the user clicks on the navigation links, get the data-slide attribute value of the link and pass that variable to the goToByScroll function
links.click(function (e) {
e.preventDefault();
dataslide = $(this).attr('data-slide');
goToByScroll(dataslide);
});
//When the user clicks on the button, get the get the data-slide attribute value of the button and pass that variable to the goToByScroll function
button.click(function (e) {
e.preventDefault();
dataslide = $(this).attr('data-slide');
goToByScroll(dataslide);
});
});
如果有人能帮我解决问题,那就太好了。
将脚本放在结束标记体(</body>
)之前,并包含Jquery库
您可能有jquery
的冲突,请在添加任何版本的jquery
(如)后尝试使用jQuery.noConflict()
<script>
jQuery.noConflict();
</script>
相关文章:
- 有没有一种方法可以通过只引用JavaScript来执行代码
- jQuery在类更改时执行代码
- 如果此代码运行,请执行代码
- Javascript等待ajax成功后再执行代码
- 如何在onclick事件执行代码时在ImageButton上设置加载gif
- php,如果我点击按钮程序重新加载页面,并且从不继续执行代码
- Javascript渲染.如何编写Javascript;t在函数调用结束之前继续执行代码
- 无法让 jQuery 以正确的顺序执行代码
- ReactJS:在带有 ajax 调用的 .map() 语句完成后执行代码
- 从一个文本框执行代码,并在另一个文本框中以 HTML 显示输出
- 自执行代码中的“this”
- 为什么Javascript不按顺序执行代码
- 如何在javascript中连续执行代码
- 加载所有图像后执行代码
- 按下多个按钮时执行代码
- 如何在检索到数据后使用drawCallback执行代码
- 等待promise解析后再执行代码
- jQuery没有为具有新id的新元素执行代码
- 如何在客户端Collection增长时立即反应性地执行代码
- 如何将变量表达式转换为可执行代码(而不是替换值)