我在我正在构建的页面中使用scrollTo jquery库,它适用于Chrome,Safari和IE 8/9,但不适用于Firefox。萤火虫告诉我,
TypeError:$(“#wrapper”)。scrollTo不是函数
这是包含scrollTo库的行
<script type="text/javascript" src="js/jquery.scrollTo.js"></script>
这是我使用scrollTo的函数
function scrollPage(currentpage,scrollpage) {
$(scrollpage).find('.text').fadeOut();
$(currentpage).find('.text').fadeOut( function(){
$('#wrapper').scrollTo( scrollpage, 1500, {
onAfter:function(){
$(scrollpage).find('.text').fadeIn();
}
});
});
}
为什么firefox不会认为scrollTo是一个函数,而我尝试过的所有其他浏览器呢?
编辑:似乎我的文件在其他计算机上工作,但不是我当前安装的Firefox。我要重新安装,看看有帮助。
解:
好吧,这似乎是一个弹出窗口拦截器造成了冲突! OP发现卡巴斯基在firefox中安装了一个安全添加,并阻止了scrollTo。
更多:http://github.com/mootools/mootools-core/issues/2202
原始邮寄:
当我的jQuery代码没有包含在$(document).ready(function() {...your jquery statements here ...});
块中时,我有时会遇到该错误。
您的函数不必在doc内部,但调用它的语句应该是。
适合我(fiddle)。你有没有在你的HTML中包含jQuery?
这就是你如何做到的(当然是在你的ScrollTo库之前):
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
而不是使用scrollTo我使用scrollIntoView,它在FireFox,Chrome和IE中工作。
示例:
var element = document.querySelector('.navbar-brand');
element.scrollIntoView();