gpt4 book ai didi

javascript - 如何使流体 anchor 在选择选项中滚动

转载 作者:行者123 更新时间:2023-11-30 17:42:39 24 4
gpt4 key购买 nike

我无法使用选择选项元素进行流畅的滚动,只能使用链接。谁能帮帮我?

jsfiddle demo !

$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});

谢谢!

最佳答案

只是做:

DEMO

$('select').on('change', function () {
$('html,body').animate({
scrollTop: $(this.value).offset().top
}, 1000);
});

并移除 onchange 内联属性

关于javascript - 如何使流体 anchor 在选择选项中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20746983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com