【问题标题】:JQuery version conflict. Bootstrap parallaxjQuery 版本冲突。自举视差
【发布时间】:2014-04-04 23:42:15
【问题描述】:

我想在一个文档中使用不同的 jQuery。 On 在 bootstrap MEGAMENU (1.11.0) 中使用,旧版本在 paralax 脚本中使用。

我的代码如下所示:

<script src="js/vendor/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
var jQuery_1_11_0 = $.noConflict(true);
 $(function() {
        window.prettyPrint && prettyPrint()
        $(document).on('click', '.yamm .dropdown-menu', function(e) {
          e.stopPropagation()
        })
      })
</script>


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
var jQuery_1_6_4 = $.noConflict(true);
$('#nav').localScroll(800);

    $('#intro').parallax("50%", 0.1);
    $('#second').parallax("50%", 0.1);
    $('.bg').parallax("50%", 0.4);
    $('#third').parallax("50%", 0.3);
</script>

这有什么问题?

【问题讨论】:

  • 嗯,你真的不应该多次包含 jQuery。你为什么要这么做?
  • 当我使用一个 jQuery 导航栏下拉菜单时,t work. When i paste second one parallax doesnt 工作。我发现这是可能的。但是我的代码中的某些地方是错误的。这是我的来源:api.jquery.com/jQuery.noConflict
  • 这是您在页面上构建代码的方式吗?
  • 您将$ 两次重新分配给专用变量,然后不使用它。您绝对应该重新阅读文档。

标签: jquery html twitter-bootstrap parallax.js


【解决方案1】:

包括您对 jQuery 的引用。

<script src="js/vendor/jquery-1.11.0.min.js" type="text/javascript"></script>


// Run Your Code in another script tag. 
<script type="text/javascript">

 $(function() {

      // This code makes no sense to me, what intent do you have here?
      // It's essentially not doing anything at all. 
      window.prettyPrint && prettyPrint();


    $(document).on('click', '.yamm .dropdown-menu', function(e) {
      e.stopPropagation();
      // What else are you trying to do here?
    });

    // Adding the calls to the plugin. 
    $('#nav').localScroll(800);
    $('#intro').parallax("50%", 0.1);
    $('#second').parallax("50%", 0.1);
    $('.bg').parallax("50%", 0.4);
    $('#third').parallax("50%", 0.3);

 });

</script>

我将调用移至 jQuery 包装函数内的视差插件。这应该可以正常工作。如果它不检查以确保所有需要 jQuery 的东西都不需要或破坏最近的 jQuery 版本。

我希望这对你有帮助。

【讨论】:

  • 感谢它帮了很多忙,但我稍微改了一下;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多