开发者

jQuery jump to id (no animation)

开发者 https://www.devze.com 2023-01-02 23:16 出处:网络
Script adds id for block, gives: <div id=\"some\">Text</div> After that page should jump for t开发者_Go百科hat id, without animation, just like we have target #some on current page li

Script adds id for block, gives:

<div id="some">Text</div>

After that page should jump for t开发者_Go百科hat id, without animation, just like we have target #some on current page link.

How to do this?

Thanks.


Try this:

 document.getElementById('some').scrollIntoView(true);


Do you just mean linking "old school" like #some

For example

<a href="#some"></a>

Done in JS with

location.href = "#some"; 


Like this:

location.href = "#some"; 


$('a[href^="#"]').click(function() {
$('html,body').animate({ scrollTop: $(this.hash).offset().top});
return false;
e.preventDefault();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号