测试地点:
https://josh-unger-4lts.squarespace.com/
我想在点击网站顶部的3行汉堡菜单时阻止文档滚动到顶部。这在向下滚动页面后不久就会显示出来。
<script>
$(document).ready(function(){
$(document).find(".Mobile-bar-menu").on("click", function(event){
event.stopPropagation();
});
});
</script>
答案 0 :(得分:0)
我建议使用此代码块直接在您的实际网站的控制台中进行测试 它有效。
// Global variable to remind the scrolled position on hamburger click
var pos=0;
$(document).find(".Mobile-bar-menu").on("click", function(event){
pos = $(window).scrollTop();
console.log(pos);
});
// On menu close, restore the scrolled position after the animation has finished.
$(".Mobile-overlay-close").click(function(){
$(".Mobile.loaded").removeClass("expand");
setTimeout(function(){
window.scrollTo(0,pos);
},400);
});
现在你应该把这些代码部分放在正确的位置......