添加新Javascript后破碎的菜单样式

时间:2012-07-29 16:42:43

标签: javascript jquery drop-down-menu mootools

我的下拉菜单如下所示:

但是,我想要一个div元素将页面顶部粘贴在某个滚动范围内,所以我在头部添加了这个代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
// <![CDATA[
$(window).scroll(function(e){
    $el = $('.fixedElement');
    if ($(this).scrollTop() > 1437 && $el.css('position') != 'fixed'){
        $('.fixedElement').css({'position': 'fixed', 'top': '0px'});
    }
    if ($(this).scrollTop() < 1437 && $el.css('position') != 'absolute'){
        $('.fixedElement').css({'position': 'absolute', 'top': '1437px'});
    }
});
// ]]>
</script>

.fixedElement在我的CSS文件中定义,然后用

引用
<div class="fixedElement">

现在,我的下拉菜单如下所示:

当我注释掉新的javascript时,菜单会恢复正常。

有关如何使用我的下拉菜单设置新javascript的任何想法?

谢谢!

编辑:

与下拉列表javascript相关的一个控制台错误是:

Uncaught TypeError: Object #<Object> has no method 'getElements'

这是引用这一行:

var links = $(this.options.id).getElements('a');

在这个javascript中:MenuMatic

当我注释掉新的javascript时,错误消失,我的菜单又回来了!

1 个答案:

答案 0 :(得分:0)

知道了。

我的下拉列表javascript正在使用MooTools库,而我的粘性div正在使用jQuery。

jQuery使用“$”作为“jQuery”的快捷方式,所以行

var links = $(this.options.id).getElements('a');

从MooTools库引用javascript会引发错误,因为jQuery已覆盖“$”的定义

通过插入

解决了这种冲突
jQuery.noConflict();

在我的jQuery脚本之前用“jQuery”替换我的jQuery脚本中的所有“$”

此处有更多信息:http://docs.jquery.com/Using_jQuery_with_Other_Libraries

另见:

jQuery and other libraries, and the usage of '$'

What is the meaning of symbol $ in jQuery?