【发布时间】:2014-02-19 17:08:38
【问题描述】:
我有以下功能:
var jump=function(e)
{
if (e){
e.preventDefault();
var target = $(this).attr("href");
}else{
var target = location.hash;
}
$('html,body').animate(
{
scrollTop: $(target).offset().top
},2000,function()
{
location.hash = target;
});
}
$('html, body').hide();
$(document).ready(function()
{
$('a[href^=#]').bind("click", jump);
if (location.hash){
setTimeout(function(){
$('html, body').scrollTop(0).show();
jump();
}, 0);
}else{
$('html, body').show();
}
});
允许滚动到特定的 div 元素
<div id="anchor_element">blabla</div>
如果我点击链接:
<a href="#anchor_element">Scroll here</a>
我希望上面的功能只有在 html 链接中包含特定的 rel 属性(例如“myscroll”)时才起作用:
<a href="#anchor_element" rel="myscroll">Scroll here</a>
如何修改此模式下的工作功能? 谢谢
【问题讨论】:
标签: javascript jquery html scroll anchor