1 /* Source: http://www.webspeaks.in/2011/07/new-gmail-like-floating-toolbar-jquery.html
2 Revision: http://jsfiddle.net/pasmalin/AyjeZ/
5 $.fn.fixFloat = function(options){
10 var options = $.extend(defaults, options);
12 var offsetTop; /**Distance of the element from the top of window**/
13 var s; /**Scrolled distance from the top of window through which we have moved**/
15 var repositionMe = true;
18 var originalOffset = tbh.position().top; /**Get the actual distance of the element from the top mychange:change to position better work**/
20 if (tbh.css('position')!='absolute') {
21 var tbhBis = $("<div></div>");
22 tbhBis.css({"display":tbh.css("display"),"visibility":"hidden"});
23 tbhBis.width(tbh.outerWidth(true));
24 tbhBis.height(tbh.outerHeight(true));
26 tbh.width(tbh.width());
27 tbh.css({'position':'absolute'});
31 $(window).scroll(function(){
32 var offsetTop = tbh.offset().top; /**Get the current distance of the element from the top **/
33 var s = parseInt($(window).scrollTop(), 10); /**Get the from the top of wondow through which we have scrolled**/
41 if(s < originalOffset){
54 tbh.addClass("floating");
58 'position' : 'absolute',
59 'top' : originalOffset,
63 tbh.removeClass("floating");