zippy1978 / jquery.scrollz

Modern scrolling for jQuery
GNU General Public License v2.0
81 stars 17 forks source link

Manually scroll to bottom or X #4

Closed jerone closed 9 years ago

jerone commented 11 years ago

I was looking for a way to manually scroll to position (in my case the bottom).

The following code was used to create this option:

var $_fn_scrollz = $.fn.scrollz;
$.fn.scrollz = function (method) {

    // method scroll to *;
    if (method === "scrollTo") {

        // scroll container to new location;
        $(this).data("markup").container.animate({ scrollTop: arguments[1] || 0 }, { duration: 750, easing: 'easeOutCubic' });

    } else if (method === "scrollToBottom") {  // method scroll to bottom;

        // scrollz container;
        var container = $(this).data("markup").container,
            offset = 3;  // 3 pixels offset to take into account;

        // scroll container to new location;
        container.stop().animate({ scrollTop: container.get(0).scrollHeight - container.height() - offset }, { duration: 750, easing: 'easeOutCubic' });

    } else {

        // execute original code;
        $_fn_scrollz.apply(this, arguments);
    }
};

Maybe you can use the code above to add this in.

Only issue I was having sometimes is that with infinity scrolling (using bottomreached event to add data and the scrolling to the bottom again), this could create a loop.

zippy1978 commented 11 years ago

Thank you !

I'll have a look at this :)