这个问题可能更多的是语法问题。我有一些简单的代码来控制一些自定义选项卡,这些选项卡在单击时会在屏幕上流动和流动。在大多数情况下,代码(尤其是动画)按预期工作并且没有问题。
<script type="text/javascript">
$('.side_drawer_face').click(function() {
if ($('#side_drawer').css("left") <= "0"){
$('#overlay_div').show();
document.getElementById('side_drawer').style.zIndex = 6000;
document.getElementById('side_drawer2').style.zIndex = 5000;
$('#side_drawer').animate({ opacity: 1.0, left: '+=406'}, 500);
$('#side_drawer2').animate({ opacity: 1.0, left: '+=406'}, 500);
} else if ($('#side_drawer').css("z-index") == "6000"){
$('#overlay_div').hide();
$('#side_drawer').animate({ opacity: 1.0, left: '-=406'}, 500);
$('#side_drawer2').animate({ opacity: 1.0, left: '-=406'}, 500);
document.getElementById('side_drawer').style.zIndex = 6000;
document.getElementById('side_drawer2').style.zIndex = 5000;
} else {
document.getElementById('side_drawer').style.zIndex = 6000;
document.getElementById('side_drawer2').style.zIndex = 5000;
}
});
$('.side_drawer_face2').click(function() {
//shows Bio div
if ($('#side_drawer2').css("left") <= "0"){
$('#overlay_div').show();
document.getElementById('side_drawer2').style.zIndex = 6000;
document.getElementById('side_drawer').style.zIndex = 5000;
$('#side_drawer').animate({ opacity: 1.0, left: '+=406'}, 500);
$('#side_drawer2').animate({ opacity: 1.0, left: '+=406'}, 500);
} else if ($('#side_drawer2').css("z-index") == "6000"){
$('#overlay_div').hide();
$('#side_drawer').animate({ opacity: 1.0, left: '-=406'}, 500);
$('#side_drawer2').animate({ opacity: 1.0, left: '-=406'}, 500);
} else {
document.getElementById('side_drawer2').style.zIndex = 6000;
document.getElementById('side_drawer').style.zIndex = 5000;
}
});
$('.clear_overlay').click(function() {
$('#overlay_div').hide();
$('#side_drawer').animate({ opacity: 1.0, left: '-=406'}, 500);
$('#side_drawer2').animate({ opacity: 1.0, left: '-=406'}, 500);
document.getElementById('side_drawer2').style.zIndex = 5000;
document.getElementById('side_drawer').style.zIndex = 6000;
});
</script>
我的问题是,在某些浏览器中(以 I 开头并以 E 结尾)在加载其他页面元素时快速单击选项卡会导致意外行为。我想做的是用文档就绪语句包装整个脚本,以便在加载页面上的所有内容之前无法执行任何功能。(脚本已经位于 html 正文的底部)