我选择带有滚动条的选项标签来查看下拉列表中的内容。我希望当我们单击选择项目时,滚动条应位于底部。
jquery code
$('document').ready(function(){
$('#textin1').click(function() {
var pos = $('#textin1').offset();
pos.top += $('#textin1').width();
$('#dropdown').fadeIn(100);
$('#dropdown').scrollTop($('#dropdown').find('li:contains("'+$('#textin1').val()+'")').position().top);
return false;
});
$('#dropdown li').click(function() {
$('#textin1').val($(this).text());
$('#dropdown li').removeClass('selected');
$(this).addClass('selected');
$(this).parent().fadeOut(100);
});
}); Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试试这个也许对你有用
const scrolling = document.getElementById("scroll"); const config = { childList: true }; const callback = function (mutationsList, observer) { for (let mutation of mutationsList) { if (mutation.type === "childList") { window.scrollTo(0, document.body.scrollHeight); } } }; const observer = new MutationObserver(callback); observer.observe(scrolling, config);