Automatically scroll to bottom of div using Tiny Scrollbar

前端 未结 4 1495
悲哀的现实
悲哀的现实 2021-01-26 10:12

I\'m coding a shoutbox and making it as user friendly as possible. It uses the Tiny Scrollbar plugin for jQuery and I want to incorporate an extra function that will allow me to

4条回答
  •  离开以前
    2021-01-26 10:44

    You could also use the native jQuery animate function to achieve the smooth auto scroll. And there is no need to alter the original tiny scrollbar script.

    //Get the heights of the overview and viewport
    oHeight = $('.overview:first').css("height");
    oHeight = oHeight.substring(0, oHeight.length-2);
    
    vHeight = $('.viewport:first').css("height");
    vHeight = vHeight.substring(0, vHeight.length-2);
    
    //Use the height values to determine how far we need to scroll
    scroll = oHeight - vHeight;
    
    //Animate it
    $('.overview:first').animate({
        top: "-"+scroll+"px"
        }, 5000, function() {
            // Animation complete.
        });
    
    //We need to do the same work for the track
    tHeight = $('.thumb:first').css("height");
    tHeight = tHeight.substring(0, tHeight.length-2);
    
    trHeight = $('.track:first').css("height");
    trHeight = trHeight.substring(0, trHeight.length-2);
    tScroll = trHeight - tHeight;
    
    
    $('.thumb:first').animate({
        top: tScroll+"px"
        }, 5000, function() {
            // Animation complete.
        }, 5000);
    });
    

提交回复
热议问题