【发布时间】:2017-03-11 23:10:30
【问题描述】:
我没有得到这个,页面只是跳转到 id 而不是动画。 也没有显示警报“点击”?
<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
【问题讨论】:
标签: javascript jquery css animation