【发布时间】:2011-05-19 10:59:05
【问题描述】:
我在锚点上有一个onclick,它会导致 2 个 div 改变它们的宽度(边栏切换的典型概念,同时放大内容)。但是,如果我在动画仍在播放时单击此锚点并再次单击它,它将从当前 div 的位置开始动画(例如 sideDiv 通常为 200px 宽度,内容为 1000px 宽度,如果我开始动画sideDiv 应该为 0,内容为 1200,但是,如果我在 side 为 100,内容为 1100 时再次单击,它们将切换回 300 和 900,这不是我想要的)。
所以,从逻辑上讲,我需要在播放动画时禁用 anchor-onclick 并再次启用它,我知道按钮的这个过程,锚点有什么类似的吗?
这是我的代码:
function toggleSideBar(e) {
barWidth = $('#resizableBar').width();
if ($('#content').width() >= "900") {
$('#content').animate({ width: ($('#content').width() - barWidth) }, 200, function () {
$('#resizableBar').animate({ width: "show" }, { duration: 200, queue: true});
});
}
else {
$('#resizableBar').animate({ width: "hide" }, 200, function () {
$('#content').animate({ width: ($('#content').width() + barWidth) }, { duration: 200, queue: true });
});
}
}
这是锚点:
<a id="btnSideDivSlide" onclick="toggleSideBar(this)" href="#">Sideslide</a>
谢谢,
丹尼斯
【问题讨论】:
标签: javascript jquery html onclick anchor