<select>
<option value="#anchor">Anchor</option>
</select>
<a id="anchor">Anchor</a>
我正在尝试让它平滑地滚动,但到目前为止还没有成功。我在网上找到的可行教程都是关于常规垂直菜单的,而不是下拉菜单。有人知道如何使其正常工作吗?我一直在使用以下内容:
<script>
$(document).ready(function(){
$('option[value^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 1000, 'swing', function () {
window.location.hash = target;
});
});
});
</script>