dist/garnish.js
function(container, elem) {
        var $elem;

        if (typeof elem === 'undefined') {
            $elem = $(container);
            $container = $elem.scrollParent();
        }
        else {
            var $container = $(container);
            $elem = $(elem);
        }

        if ($container.prop('nodeName') === 'HTML' || $container[0] === Garnish.$doc[0]) {
            $container = Garnish.$win;
        }

        var scrollTop = $container.scrollTop(),
            elemOffset = $elem.offset().top;

        var elemScrollOffset;

        if ($container[0] === window) {
            elemScrollOffset = elemOffset - scrollTop;
        }
        else {
            elemScrollOffset = elemOffset - $container.offset().top;
        }

        var targetScrollTop = false;

        // Is the element above the fold?
        if (elemScrollOffset < 0) {
            targetScrollTop = scrollTop + elemScrollOffset - 10;
        }
        else {
            var elemHeight = $elem.outerHeight(),
                containerHeight = ($container[0] === window ? window.innerHeight : $container[0].clientHeight);

            // Is it below the fold?
            if (elemScrollOffset + elemHeight > containerHeight) {
                targetScrollTop = scrollTop + (elemScrollOffset - (containerHeight - elemHeight)) + 10;
            }
        }

        if (targetScrollTop !== false) {
            // Velocity only allows you to scroll to an arbitrary position if you're scrolling the main window
            if ($container[0] === window) {
                $('html').velocity('scroll', {
                    offset: targetScrollTop + 'px',
                    mobileHA: false
                });
            }
            else {
                $container.scrollTop(targetScrollTop);
            }
        }
    }
function(container, elem) {
        var $elem;

        if (typeof elem === 'undefined') {
            $elem = $(container);
            $container = $elem.scrollParent();
        }
        else {
            var $container = $(container);
            $elem = $(elem);
        }

        if ($container.prop('nodeName') === 'HTML' || $container[0] === Garnish.$doc[0]) {
            $container = Garnish.$win;
        }

        var scrollTop = $container.scrollTop(),
            elemOffset = $elem.offset().top;

        var elemScrollOffset;

        if ($container[0] === window) {
            elemScrollOffset = elemOffset - scrollTop;
        }
        else {
            elemScrollOffset = elemOffset - $container.offset().top;
        }

        var targetScrollTop = false;

        // Is the element above the fold?
        if (elemScrollOffset < 0) {
            targetScrollTop = scrollTop + elemScrollOffset - 10;
        }
        else {
            var elemHeight = $elem.outerHeight(),
                containerHeight = ($container[0] === window ? window.innerHeight : $container[0].clientHeight);

            // Is it below the fold?
            if (elemScrollOffset + elemHeight > containerHeight) {
                targetScrollTop = scrollTop + (elemScrollOffset - (containerHeight - elemHeight)) + 10;
            }
        }

        if (targetScrollTop !== false) {
            // Velocity only allows you to scroll to an arbitrary position if you're scrolling the main window
            if ($container[0] === window) {
                $('html').velocity('scroll', {
                    offset: targetScrollTop + 'px',
                    mobileHA: false
                });
            }
            else {
                $container.scrollTop(targetScrollTop);
            }
        }
    }
function ( container , elem ) { var $elem ; if ( typeof elem === 'undefined' ) { $elem = $ ( container ) ; $container = $elem . scrollParent ( ) ; } else { var $container = $ ( container ) ; $elem = $ ( elem ) ; } if ( $container . prop ( 'nodeName' ) === 'HTML' || $container [ 0 ] === Garnish . $doc [ 0 ] ) { $container = Garnish . $win ; } var scrollTop = $container . scrollTop ( ) , elemOffset = $elem . offset ( ) . top ; var elemScrollOffset ; if ( $container [ 0 ] === window ) { elemScrollOffset = elemOffset - scrollTop ; } else { elemScrollOffset = elemOffset - $container . offset ( ) . top ; } var targetScrollTop = false ; // Is the element above the fold? if ( elemScrollOffset < 0 ) { targetScrollTop = scrollTop + elemScrollOffset - 10 ; } else { var elemHeight = $elem . outerHeight ( ) , containerHeight = ( $container [ 0 ] === window ? window . innerHeight : $container [ 0 ] . clientHeight ) ; // Is it below the fold? if ( elemScrollOffset + elemHeight > containerHeight ) { targetScrollTop = scrollTop + ( elemScrollOffset - ( containerHeight - elemHeight ) ) + 10 ; } } if ( targetScrollTop !== false ) { // Velocity only allows you to scroll to an arbitrary position if you're scrolling the main window if ( $container [ 0 ] === window ) { $ ( 'html' ) . velocity ( 'scroll' , { offset : targetScrollTop + 'px' , mobileHA : false } ) ; } else { $container . scrollTop ( targetScrollTop ) ; } } }
Scrolls a container element to an element within it.

@param {object} container Either an actual element or a jQuery collection.
@param {object} elem      Either an actual element or a jQuery collection.
Scrolls a container element to an element within it .