简体   繁体   English

如何在页面上使用两个JavaScript

[英]How to get two javascripts to work on one page

this has been something that has baffled me for the longest with working with javscript. 在使用javscript的过程中,这一直使我感到困惑。 First there are two javascript codes i'm using. 首先,我正在使用两个JavaScript代码。

Here is the first one 这是第一个

  <!-- The JavaScript -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>  
    <script type="text/javascript" src="jquery.easing.1.3.js"></script>
    <script type="text/javascript">
        $(function() {
            $('ul.nav a').bind('click',function(event){
                var $anchor = $(this);

                $('html, body').stop().animate({
                    scrollTop: $($anchor.attr('href')).offset().top
                }, 1500,'easeInOutExpo');
                /*
                if you don't want to use the easing effects:
                $('html, body').stop().animate({
                    scrollTop: $($anchor.attr('href')).offset().top
                }, 1000);
                */
                event.preventDefault();
            });
        });
    </script>

The Above code is used to make the page transition from one div to another smoothly. 上述代码用于使页面从一个div平滑过渡到另一个div。 Like this ---> http://tympanus.net/Tutorials/WebsiteScrolling/index_vertical.html 像这样---> http://tympanus.net/Tutorials/WebsiteScrolling/index_vertical.html

here is the second one 这是第二个

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://littleladyenterprises.com/wp-content/themes/blackchic/WebsiteScrolling/css/jquery.sudoSlider.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var sudoSlider = $("#slider").sudoSlider({
            numeric: false,
            continuous:true
        });
 var sudoSlider2 = $("#slider2").sudoSlider();
});

</script>

This code is basically a slider 这段代码基本上是一个滑块

Ok, by placing the slider script last it works but it makes the fisrt script, the page transition script not work. 好的,通过将滑块脚本放置在最后,它可以工作,但是它使fisrt脚本,页面转换脚本不起作用。 I have seen this with many different scripts, I am not too JS saavy, but can anyone tell me how to make them both work on one page. 我已经用很多不同的脚本看到了这一点,但我对JS不太了解,但是谁能告诉我如何使它们都在一页上工作。

Get rid of the second call to the jquery library: 摆脱对jquery库的第二个调用:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

What is happening is you are overwriting the first instance of jquery, causing any bindings configured with it to be lost (ie the first script) 发生的是您正在覆盖jquery的第一个实例,从而导致配置了它的所有绑定丢失(即第一个脚本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM