jQuery动画不能在Firefox的IE中工作
jQuery animate not working in IE of Firefox?
我有一个功能,我想滚动我的网页水平,我有以下工作良好的Chrome
只有它绊倒,当我来测试它在Firefox
和Internet Explorer
。有人能看出我的语法中有什么明显的错误吗?
/* Navigtion */
$('nav ol li a').click(function(e){
e.preventDefault();
$('nav').find('.active').removeClass('active');
$(this).addClass('active');
if( $(this).hasClass('sectionOne') ){
scrollTo = $('.section-one').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionTwo') ){
scrollTo = $('.section-two').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionThree') ){
scrollTo = $('.section-three').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionFour') ){
scrollTo = $('.section-four').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionFive') ){
scrollTo = $('.section-five').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionSix') ){
scrollTo = $('.section-six').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
} else if( $(this).hasClass('sectionSeven') ){
scrollTo = $('.section-seven').position().left;
$('body').animate({'scrollLeft': scrollTo}, 800);
}
});
不同的浏览器将滚动条附加到不同的元素上,你必须这样做
$('html, body').animate({'scrollLeft': scrollTo}, 800);
试着找出一个比所有这些if/else语句更好的方法,这里有一个例子。
为锚添加数据属性
<nav>
<ol>
<li>
<a data-section="section-one" ....
,你可以删除所有的if/else,用两行
做同样的事情var scrollTo = $('.' + $(this).data('section')).position().left;
$('html, body').animate({'scrollLeft': scrollTo}, 800);
try:
$('body').animate({'scrollLeft': scrollTo}, 800);
$('html').animate({'scrollLeft': scrollTo}, 800);
有的浏览器支持'html',有的支持'body'
相关文章:
- Target=_blank don'我不在mozilla和IE工作
- jQUery Code没有'我不在IE工作
- 为什么这个书签脚本是't在IE工作
- 类构造函数super()没有'我不在IE工作
- onmousemove=null不会'我不在IE工作
- execCommand('另存为',true,'data.csv');不在IE工作
- 努力让第n个有悬停的孩子在IE工作
- Javascript Groovy按钮没有'我不在IE工作
- 属性='值'jquery选择没有'我不在IE工作
- atob不在IE工作
- 将图像附加到富文本编辑器dosen'我不在IE工作
- javascript没有'I don’我一直在IE工作
- 使用插件制作移动滑动导航,但它没有'我不在IE工作
- Video.js没有'我不在FF、IE工作
- dojo on.emit”;点击“;以及“;改变“;不在IE工作
- 为什么这个工具提示没有'不在IE工作吗?错误:应为对象
- document.getElementById('a').click()没有't在IE工作
- 插入符号插件的jquery;我不在IE工作
- 聚合物:点击事件在IE工作,但不是Chrome.如何修复
- 如何使IE工作预期与正则表达式提供的函数参数在拆分函数