0
考虑下面的JS代码:jQuery + window.location.hash和相同页面锚点 - 不一致的行为?
<script type="text/javascript">
$(function() {
// Check if landing on the page with a hash
if (window.location.hash.length) {
$('html,body').animate({scrollTop: 200}, 100);
return false;
}
// Same-page anchors
$('a[href*=#]').click(function() {
// ... find the target based on the div and animate the scrollTop property again
}
});
});
</script>
它的作用是第一次检查,如果登陆页面上有#anchor或者如果用户点击了同一页#anchor和简单动画与目标DIV相应的ID。
问题是这两个工作可以交替使用:如果你登陆一个带有散列符号的页面,该页面将动画到div ID,但随后的相同页面链接不会被绑定的“点击”拦截,事件(我也尝试用live()绑定它,没有什么区别)
如果你用一个干净的URL着陆页面,链接将再次工作。我究竟做错了什么?
jeez,我觉得哑巴。谢啦!!! –
这是你永远不会发现的错误;)只是看起来不错... – Niko