我不懂这是怎么回事,页面只是跳到了ID位置,没有动画效果。同时警告“click”的内容也没有显示?
<script>
jQuery(document).ready(function($) {
alert('start');
$('ul#menu-sde-menu li a[href^="#"]').on('click', function(event) {
alert("click");
var target = $(this.getAttribute('href'));
if (target.length) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
});
一个简单的菜单
<ul id="menu-sde-menu"><li><a href="http://localhost/testdomain/sde/#link1">link 1</a></li><li><a href="http://localhost/testdomain/sde/#link2">link 2</a></li></ul>
我尝试使用https://www.abeautifulsite.net/smoothly-scroll-to-an-element-without-a-jquery-plugin-2来平滑地滚动到一个元素。