Inna
Inna

Reputation: 433

Scroll function doesnt work after using some elements

Im using a scroll function this works perfect whenever I use normal text for it, but whenever I use Text<br>Text<p> it wont scroll automaticly because there is a<p> or <br> what to do to make it also scroll for once with other elements.

And is there a simple way to use it for all $('#scrollDiv') istead of copy paste it above every line? Example usage:

//This scrolls correct
$('#scrollDiv').append('Hello world!');
scrollDiv($('.scroll-text:eq(0)'));

//This wont work scrolling
$('#scrollDiv').append('Hello<br>world!');
scrollDiv($('.scroll-text:eq(0)'));

//This also wont work
$('#scrollDiv').append('<span style="font-size:100px;">Hello</span>');
scrollDiv($('.scroll-text:eq(0)'));



function scrollDiv($div, h){
    var scrollHeight = $div[0].scrollHeight;
    var scrollTop = $div[0].scrollTop;
    var height = $div[0].clientHeight;
    var h_invisible = scrollHeight - scrollTop - height;

    if(h){
        if(h>h_invisible){
            $div.scrollTop(1e5);
        }
    }else{
        if(15>h_invisible){
            $div.scrollTop(1e5);
        }
    }
}

Upvotes: 0

Views: 28

Answers (1)

Hakan Kose
Hakan Kose

Reputation: 1656

scrollDiv($('.scroll-text:eq(0)'), 50);

could help you out..

Upvotes: 1

Related Questions