是否可以让滚动条默认位于底部?
P粉795311321
P粉795311321 2023-09-15 20:08:44
[CSS3讨论组]

我选择带有滚动条的选项标签来查看下拉列表中的内容。我希望当我们单击选择项目时,滚动条应位于底部。

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);
    });
});

P粉795311321
P粉795311321

全部回复(1)
P粉287726308

试试这个也许对你有用

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);
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号