-
Notifications
You must be signed in to change notification settings - Fork 0
/
jq-sticky-anything.min.js
5 lines (4 loc) · 1.43 KB
/
jq-sticky-anything.min.js
1
2
3
4
5
/**
* @preserve Sticky Anything 1.1.3 | @senff | GPL2 Licensed
*/
(function(e){function t(t,n,r){var i=e(".original").offset();orgElementTop=i.top;var s=window,o="inner";if(!("innerWidth"in window)){o="client";s=document.documentElement||document.body}viewport=s[o+"Width"];if(e(window).scrollTop()>=orgElementTop-t&&viewport>=n&&viewport<=r){orgElement=e(".original");coordsOrgElement=orgElement.offset();leftOrgElement=coordsOrgElement.left;widthOrgElement=orgElement.css("width");e(".cloned").css("left",leftOrgElement+"px").css("top",t+"px").css("width",widthOrgElement).show();e(".original").css("visibility","hidden")}else{e(".cloned").hide();e(".original").css("visibility","visible")}}e.fn.stickThis=function(n){var r=e.extend({top:0,minscreenwidth:0,maxscreenwidth:99999,zindex:1,debugmode:false},n);var i=e(this).length;if(i<1){if(r.debugmode==true){console.error("STICKY ANYTHING DEBUG: There are no elements with the class/ID you selected.")}}else if(i>1){if(r.debugmode==true){console.error("STICKY ANYTHING DEBUG: There is more than one element with the class/ID you selected. You can only make ONE element sticky.")}}else{e(this).addClass("original").clone().insertAfter(this).addClass("cloned").css("position","fixed").css("top",r.top+"px").css("margin-top","0").css("margin-left","0").css("z-index",r.zindex).removeClass("original").hide();checkElement=setInterval(function(){t(r.top,r.minscreenwidth,r.maxscreenwidth)},10)}return this}})(jQuery)