Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery代码未执行_Javascript_Jquery - Fatal编程技术网

Javascript Jquery代码未执行

Javascript Jquery代码未执行,javascript,jquery,Javascript,Jquery,我目前正在学习jQuery。我对以下代码有一些问题。我试图使用一些按钮来移动我的网站,但一旦我点击它们,它似乎就不起作用了。下面是我的jquery代码 jQuery(document).ready(function ($) { //initialise Stellar.js $(window).stellar(); //Cache some variables var links = $('.navigation').find('li'); slide =

我目前正在学习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);
    });
});

如果有人能帮我解决我的问题,那就太好了。

将脚本放在结束标记正文之前(
),并包含Jquery库将脚本放在结束标记正文之前(
)并包括Jquery库

在添加任何版本的
Jquery
后,您可能会遇到与Jquery冲突的问题,例如

<script>
     jQuery.noConflict();
</script>

jQuery.noConflict();

添加任何版本的
jquery
后,您可能会与
jquery
发生冲突,例如

<script>
     jQuery.noConflict();
</script>

jQuery.noConflict();

您是否添加了jQuery库?jQuery库正在加载吗?您在浏览器控制台中遇到了什么错误?我认为您必须将
var
添加到上面缓存的var中。不添加会使其成为全局性的,因此可能会导致一些问题。请提供一个JSFIDLE示例,以便我们提供帮助。这是整个代码代码,代码似乎还可以,您是否在
控制台中有一些
错误
?是否添加了jQuery库?jQuery库正在加载吗?您在浏览器控制台中遇到了什么错误?我认为您必须将
var
添加到上面缓存的var中。不添加会使其具有全局性,因此可能会导致一些问题。请提供一个JSFIDLE示例,以便我们能够提供帮助。这是整个代码代码。代码似乎还可以,您是否在
控制台中有一些
错误
?很抱歉,我不明白。我应该在我的html文件下添加这个吗?很抱歉,我不明白。我应该把它添加到我的html文件下吗?