Swift
Swift

Reputation: 820

Go to particular div without scroll

Need to land a particular element on click but without scrolling. Below I have a code but it is scrolling to a particular element on click, Is there any way to go to a particular HTML element without scroll?

$("#button").click(function() {
    $("html, body).animate({
        scrollTop: $("#myelement").offset().top
    }, 2000);
});

Upvotes: 0

Views: 1038

Answers (2)

Swift
Swift

Reputation: 820

Below code is working fine. Now, it is going on top instantly without animation. When i am firing click event..

$("#button").click(function() {
     $("html, body").scrollTop(0);
});

Upvotes: 0

Akash Gupta
Akash Gupta

Reputation: 105

<a href="#test" id="GoToAtag">Go to p tag</a>
<div style="background-color:lightblue;height:800px" >

</div>

<p id="test">This is some text.</p>
<a href="#GoToAtag">Go to a tag</a>

Check this one for move to any element using ID and anchor or try this jsfiddle.net/thepeanut/ohhffte6 url

Upvotes: 1

Related Questions