suppose I have a button on www.domain.com
linking to a lower part of the page through an anchor tag <a href="#destination">text link</a>
is it possible to prevent the url in url bar of the browser from showing www.domain.com/#destination
?
thanks
Use jquery like this:
$("#down").click(function () {
$('html,body').animate({
scrollTop: $("#b").offset().top
});
});
$("#up").click(function ()
$('html,body').animate({
scrollTop: $("#a").offset().top
});
})
Hope this helps.
fiddle:
You can use this:
$("a.anchor").on("click", function(e) { e.preventDefault(); $(window).scrollTop($($(this).attr('href')).offset().top); });
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <a href="#second" class="anchor">Second</a> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <h2 id="second">Second Part</h2>
Now the anchor link shows the address on hover, But scrolls to destination instead of navigation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.