JQuery .animate()仅适用于Chrome浏览器
JQuery .animate() only works in Chrome
我使用JQuery .animate()函数在容器div中滑动div。这在Google Chrome中没有问题,但当我在Firefox或IE中尝试时,div变成乱码混乱,实际上不会滑动。我是一个新的Javascript和无知的浏览器兼容性的方式,谁能指出我在正确的方向?以下是相关代码:
HTML<div id="slider">
<div id="main" class="content">
</div>
<div id="projects" class="content">
</div>
<div id="about" class="content">
</div>
<div id="contact" class="content">
</div>
</div>
CSS #slider {
width: 100px;
height: 100px;
overflow: hidden;
position: relative;
}
#main {
background-color: red;
width: inherit;
height: inherit;
position: absolute;
}
#projects {
background-color: blue;
width: inherit;
height: inherit;
position: absolute;
}
#about {
background-color: yellow;
width: inherit;
height: inherit;
position: absolute;
}
#contact {
background-color: green;
width: inherit;
height: inherit;
position: absolute;
}
.content {
left: 0;
top: 0;
}
JavaScript $(document).ready(function() {
var contentWidth = '100px';
for( var i=0; i < 2; i++) {
$('.gallery' + (i + 1)).colorbox({ opacity:0.5 , rel:'gallery' + (i+1)});
}
$('.content').css({
position: 'absolute',
left: contentWidth
});
$('#main').addClass('visible');
document.getElementById('main').style.left = "0";
$("li a").click(function () {
event.preventDefault();
var $blockID = $( $(this).attr('href') );
if ($blockID.hasClass('visible')) { return; }
$('.content.visible')
.removeClass('visible')
.animate({ left: '-=100px' }, {
duration: 'slow',
complete: function () {
$(this).css('left', '100px');
}
}
);
$blockID
.addClass('visible')
.animate({ left: 0 }, {duration: 'slow'});
});
});
JSFiddle: http://jsfiddle.net/bwvVZ/
我也可以提供一个链接到有问题的网站,虽然我会推迟,因为我不确定它是否违反规定。任何帮助都非常感激!
您缺少单击处理程序中的event
参数
$("li a").click(function(){
event.preventDefault();
//...
});
应该是
$("li a").click(function (event){
event.preventDefault();
//...
});
。
不能在IE自己测试,但这修复了Firefox和returnValue应该修复IE。CSSDeck测试-我无法从当前位置访问jsfiddle。
$("li a").click(function (event){
event.returnValue = false; //ie
if(event.preventDefault) //prevents error if not found
event.preventDefault();
var $blockID = $($(this).attr('href'));
...
相关文章:
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- Regex不适用于Firefox,但适用于Chrome
- 关闭当前选项卡并打开一个新的-仅适用于Chrome
- 向下滚动时隐藏菜单,向上滚动时显示,适用于Chrome,不适用于Safari(手机)
- Mozilla并没有完美地执行这段代码,尽管它适用于Chrome和IE
- Angularjs ng-options 问题仅适用于 Chrome 浏览器
- 支持 JavaScript 的检查例程适用于 Chrome/Opera/IE,但不适用于 Firefox/Safari
- javascript单选按钮验证,适用于chrome,不适用于IE
- getElementsByTagName未保存(仅适用于chrome)
- 在bookmarklet中使用@import和@font face(适用于Chrome,但不适用于Firefox)
- Ajax成功回调仅适用于Chrome
- ScrollTop适用于Chrome和Edge,但不适用于Firefox
- jQuery适用于Chrome、Firefox、IE,但不适用于iPhone
- minlength仅适用于Chrome
- 自动完成功能适用于Chrome,但不适用于IE
- Javascript仅适用于Chrome
- formatDate JavaScript 函数仅适用于 Chrome
- Javascript String to Date适用于Chrome,而不是FF或Safari
- 文件上传代码适用于Chrome和Mozilla,但不适用于IE 8,9
- 地理编码器仅适用于chrome,不适用于Firefox / IE / android