Max*_*Max 4 javascript firefox jquery internet-explorer cross-browser
我正在使用JQuery .animate()函数来滑动容器div中的div.这在谷歌浏览器中没有问题,但是当我尝试使用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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
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'});
});
});
Run Code Online (Sandbox Code Playgroud)
JSFiddle:http://jsfiddle.net/bwvVZ/
我也可以提供相关网站的链接,虽然我会推迟,因为我不确定它是否违反规则.任何帮助深表感谢!
您缺少event点击处理程序中的参数
$("li a").click(function(){
event.preventDefault();
//...
});
Run Code Online (Sandbox Code Playgroud)
它应该是
$("li a").click(function (event){
event.preventDefault();
//...
});
Run Code Online (Sandbox Code Playgroud)
演示.
| 归档时间: |
|
| 查看次数: |
461 次 |
| 最近记录: |