[英]disable url change when link to a different part of the same page is clicked
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>
假设我在
www.domain.com
上有一个按钮,该按钮通过定位标记<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
? 是否可以防止浏览器的网址栏中的网址显示
www.domain.com/#destination
?
thanks 谢谢
Use jquery like this: 像这样使用jquery:
$("#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. 现在,锚链接显示悬停时的地址,但是滚动到目标而不是导航。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.