search

Home  >  Q&A  >  body text

Is it possible to have the scrollbar at the bottom by default?

I select the option label with scrollbar to view the contents of the dropdown list. I want that when we click to select an item, the scrollbar should be at the bottom.

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粉795311321P粉795311321437 days ago739

reply all(1)I'll reply

  • P粉287726308

    P粉2877263082023-09-16 17:53:15

    Try this maybe it will work for you

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

    reply
    0
  • Cancelreply