【发布时间】:2015-12-14 05:12:48
【问题描述】:
<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>
【问题讨论】:
标签: javascript jquery html css dropdown