diff --git a/example/js/stickUp.js b/example/js/stickUp.js index 7d9e861..f4dfb6e 100644 --- a/example/js/stickUp.js +++ b/example/js/stickUp.js @@ -77,14 +77,17 @@ function($) { //console.log(varscroll); if(varscroll > testView){ $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq('+i+') a')[0].href.split("#")[1]); $('.'+itemClass+':eq('+i+')').addClass(itemHover); } else if(varscroll < 50){ $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq(0) a')[0].href.split("#")[1]); $('.'+itemClass+':eq(0)').addClass(itemHover); } } if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) { $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq('+i+') a')[0].href.split("#")[1]); $('.'+itemClass+':eq('+i+')').addClass(itemHover); } if(scrollDir == 'up') { diff --git a/example/js/stickUp.min.js b/example/js/stickUp.min.js index 88dc671..14bf366 100644 --- a/example/js/stickUp.min.js +++ b/example/js/stickUp.min.js @@ -1 +1,7 @@ -jQuery(function($){$(document).ready(function(){var contentButton = [];var contentTop = [];var content = [];var lastScrollTop = 0;var scrollDir = '';var itemClass = '';var itemHover = '';var menuSize = null;var stickyHeight = 0;var stickyMarginB = 0;var currentMarginT = 0;var topMargin = 0;$(window).scroll(function(event){var st = $(this).scrollTop();if (st > lastScrollTop){scrollDir = 'down';} else {scrollDir = 'up';}lastScrollTop = st;});$.fn.stickUp = function( options ) {$(this).addClass('stuckMenu');var objn = 0;if(options != null) {for(var o in options.parts) {if (options.parts.hasOwnProperty(o)){content[objn] = options.parts[objn];objn++;}}if(objn == 0) {console.log('error:needs arguments');}itemClass = options.itemClass;itemHover = options.itemHover;if(options.topMargin != null) {if(options.topMargin == 'auto') {topMargin = parseInt($('.stuckMenu').css('margin-top'));} else {if(isNaN(options.topMargin) && options.topMargin.search("px") > 0){topMargin = parseInt(options.topMargin.replace("px",""));} else if(!isNaN(parseInt(options.topMargin))) {topMargin = parseInt(options.topMargin);} else {console.log("incorrect argument, ignored.");topMargin = 0;} }} else {topMargin = 0;}menuSize = $('.'+itemClass).size();}stickyHeight = parseInt($(this).height());stickyMarginB = parseInt($(this).css('margin-bottom'));currentMarginT = parseInt($(this).next().closest('div').css('margin-top'));vartop = parseInt($(this).offset().top);};$(document).on('scroll', function() {varscroll = parseInt($(document).scrollTop());if(menuSize != null){for(var i=0;i < menuSize;i++){contentTop[i] = $('#'+content[i]+'').offset().top;function bottomView(i) {contentView = $('#'+content[i]+'').height()*.4;testView = contentTop[i] - contentView;if(varscroll > testView){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);} else if(varscroll < 50){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq(0)').addClass(itemHover);}}if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) {$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);}if(scrollDir == 'up') {bottomView(i);}}}if(vartop < varscroll + topMargin){$('.stuckMenu').addClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': stickyHeight + stickyMarginB + currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","fixed");$('.isStuck').css({top: '0px'}, 10, function(){});};if(varscroll + topMargin < vartop){$('.stuckMenu').removeClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","relative");};});});}); \ No newline at end of file +jQuery(function(s){s(document).ready(function(){var t=[],e=[],n=0,o="",r="",a="",l=null,i=0,c=0,u=0,p=0 +s(window).scroll(function(t){var e=s(this).scrollTop() +o=e>n?"down":"up",n=e}),s.fn.stickUp=function(t){s(this).addClass("stuckMenu") +var n=0 +if(null!=t){for(var o in t.parts)t.parts.hasOwnProperty(o)&&(e[n]=t.parts[n],n++) +0==n&&console.log("error:needs arguments"),r=t.itemClass,a=t.itemHover,null!=t.topMargin?"auto"==t.topMargin?p=parseInt(s(".stuckMenu").css("margin-top")):isNaN(t.topMargin)&&t.topMargin.search("px")>0?p=parseInt(t.topMargin.replace("px","")):isNaN(parseInt(t.topMargin))?(console.log("incorrect argument, ignored."),p=0):p=parseInt(t.topMargin):p=0,l=s("."+r).size()}i=parseInt(s(this).height()),c=parseInt(s(this).css("margin-bottom")),u=parseInt(s(this).next().closest("div").css("margin-top")),vartop=parseInt(s(this).offset().top)},s(document).on("scroll",function(){function n(n){contentView=.4*s("#"+e[n]).height(),testView=t[n]-contentView,varscroll>testView?(s("."+r).removeClass(a),history.pushState(null,null,"#"+s(".menuItem:eq("+n+") a")[0].href.split("#")[1]),s("."+r+":eq("+n+")").addClass(a)):varscroll<50&&(s("."+r).removeClass(a),history.pushState(null,null,"#"+s(".menuItem:eq(0) a")[0].href.split("#")[1]),s("."+r+":eq(0)").addClass(a))}if(varscroll=parseInt(s(document).scrollTop()),null!=l)for(var v=0;l>v;v++)t[v]=s("#"+e[v]).offset().top,"down"==o&&varscroll>t[v]-50&&varscroll testView){ $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq('+i+') a')[0].href.split("#")[1]); $('.'+itemClass+':eq('+i+')').addClass(itemHover); } else if(varscroll < 50){ $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq(0) a')[0].href.split("#")[1]); $('.'+itemClass+':eq(0)').addClass(itemHover); } } if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) { $('.'+itemClass).removeClass(itemHover); + history.pushState(null, null, "#" + $('.menuItem:eq('+i+') a')[0].href.split("#")[1]); $('.'+itemClass+':eq('+i+')').addClass(itemHover); } if(scrollDir == 'up') { diff --git a/stickUp.min.js b/stickUp.min.js index 88dc671..14bf366 100644 --- a/stickUp.min.js +++ b/stickUp.min.js @@ -1 +1,7 @@ -jQuery(function($){$(document).ready(function(){var contentButton = [];var contentTop = [];var content = [];var lastScrollTop = 0;var scrollDir = '';var itemClass = '';var itemHover = '';var menuSize = null;var stickyHeight = 0;var stickyMarginB = 0;var currentMarginT = 0;var topMargin = 0;$(window).scroll(function(event){var st = $(this).scrollTop();if (st > lastScrollTop){scrollDir = 'down';} else {scrollDir = 'up';}lastScrollTop = st;});$.fn.stickUp = function( options ) {$(this).addClass('stuckMenu');var objn = 0;if(options != null) {for(var o in options.parts) {if (options.parts.hasOwnProperty(o)){content[objn] = options.parts[objn];objn++;}}if(objn == 0) {console.log('error:needs arguments');}itemClass = options.itemClass;itemHover = options.itemHover;if(options.topMargin != null) {if(options.topMargin == 'auto') {topMargin = parseInt($('.stuckMenu').css('margin-top'));} else {if(isNaN(options.topMargin) && options.topMargin.search("px") > 0){topMargin = parseInt(options.topMargin.replace("px",""));} else if(!isNaN(parseInt(options.topMargin))) {topMargin = parseInt(options.topMargin);} else {console.log("incorrect argument, ignored.");topMargin = 0;} }} else {topMargin = 0;}menuSize = $('.'+itemClass).size();}stickyHeight = parseInt($(this).height());stickyMarginB = parseInt($(this).css('margin-bottom'));currentMarginT = parseInt($(this).next().closest('div').css('margin-top'));vartop = parseInt($(this).offset().top);};$(document).on('scroll', function() {varscroll = parseInt($(document).scrollTop());if(menuSize != null){for(var i=0;i < menuSize;i++){contentTop[i] = $('#'+content[i]+'').offset().top;function bottomView(i) {contentView = $('#'+content[i]+'').height()*.4;testView = contentTop[i] - contentView;if(varscroll > testView){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);} else if(varscroll < 50){$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq(0)').addClass(itemHover);}}if(scrollDir == 'down' && varscroll > contentTop[i]-50 && varscroll < contentTop[i]+50) {$('.'+itemClass).removeClass(itemHover);$('.'+itemClass+':eq('+i+')').addClass(itemHover);}if(scrollDir == 'up') {bottomView(i);}}}if(vartop < varscroll + topMargin){$('.stuckMenu').addClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': stickyHeight + stickyMarginB + currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","fixed");$('.isStuck').css({top: '0px'}, 10, function(){});};if(varscroll + topMargin < vartop){$('.stuckMenu').removeClass('isStuck');$('.stuckMenu').next().closest('div').css({'margin-top': currentMarginT + 'px'}, 10);$('.stuckMenu').css("position","relative");};});});}); \ No newline at end of file +jQuery(function(s){s(document).ready(function(){var t=[],e=[],n=0,o="",r="",a="",l=null,i=0,c=0,u=0,p=0 +s(window).scroll(function(t){var e=s(this).scrollTop() +o=e>n?"down":"up",n=e}),s.fn.stickUp=function(t){s(this).addClass("stuckMenu") +var n=0 +if(null!=t){for(var o in t.parts)t.parts.hasOwnProperty(o)&&(e[n]=t.parts[n],n++) +0==n&&console.log("error:needs arguments"),r=t.itemClass,a=t.itemHover,null!=t.topMargin?"auto"==t.topMargin?p=parseInt(s(".stuckMenu").css("margin-top")):isNaN(t.topMargin)&&t.topMargin.search("px")>0?p=parseInt(t.topMargin.replace("px","")):isNaN(parseInt(t.topMargin))?(console.log("incorrect argument, ignored."),p=0):p=parseInt(t.topMargin):p=0,l=s("."+r).size()}i=parseInt(s(this).height()),c=parseInt(s(this).css("margin-bottom")),u=parseInt(s(this).next().closest("div").css("margin-top")),vartop=parseInt(s(this).offset().top)},s(document).on("scroll",function(){function n(n){contentView=.4*s("#"+e[n]).height(),testView=t[n]-contentView,varscroll>testView?(s("."+r).removeClass(a),history.pushState(null,null,"#"+s(".menuItem:eq("+n+") a")[0].href.split("#")[1]),s("."+r+":eq("+n+")").addClass(a)):varscroll<50&&(s("."+r).removeClass(a),history.pushState(null,null,"#"+s(".menuItem:eq(0) a")[0].href.split("#")[1]),s("."+r+":eq(0)").addClass(a))}if(varscroll=parseInt(s(document).scrollTop()),null!=l)for(var v=0;l>v;v++)t[v]=s("#"+e[v]).offset().top,"down"==o&&varscroll>t[v]-50&&varscroll