dutchcelt/Keep-in-View

An alternative method to implement

Closed this issue · 1 comments

To scratch my own itch, I implemented the similar function in the code sample below, though didn't generalize it to a plugin.
Just paste here for a reference, basically a one-line implementation if unbind and name collision elusion is not required.

        var alwaysTopTips = function(e) {
           //if it's just div etc.
           //$( "#the_target" ).position({of: window, my: 'top', at: 'top', offset:0, collision: 'flip'});
           //if it's a jQuery UI dialog
           // $( "#the_target" ).dialog({ position: ['center' , 'top']  });
        };

        $(window).bind('scroll', alwaysTopTips);

        //later if need to unbind
        $(window).unbind('scroll', alwaysTopTips);

I've implemented a variation of this for the next push which will include more examples.

var staysticky = function(){
    $elem.removeAttr('style');
    options.w = $elem.width();
    options.h = $elem.height();
    offset = $elem.offset();
    setElem(); 
}

$elem.on('update', staysticky);
$(window).on('resize', staysticky).on('scroll load', setElem);