diff --git a/readme.md b/readme.md index 80462f4..45753cc 100644 --- a/readme.md +++ b/readme.md @@ -180,6 +180,10 @@ Alternatively, you can *force* the scroll by calling the method with a force arg `scrollimate.saScroll('force')` +There is also a provision for a callback, just remember to decide on the force parameter first. Usage: + +`scrollimate.saScroll( false, you-callback() )` + _ diff --git a/scrollimate.js b/scrollimate.js index 46aa758..ac8a1e4 100644 --- a/scrollimate.js +++ b/scrollimate.js @@ -203,8 +203,10 @@ var scrollimate = (function($){ * Page is animated to scroll from the top to the element that that matches * the href attribute. * return false to prevent default + * you can pass a callback into the function call, which will execute as soon as the animation is over */ - var saScroll = function(force) { + var saScroll = function(force, callback) { + callback = callback || false; console.log('saScroll initiated'); $('[href^="#"]').click(function(){ var $this = $(this); @@ -225,6 +227,9 @@ var scrollimate = (function($){ scrollTop: $( $this.attr('href') ).offset().top }, smoothAnchorScrollTime).promise().then(function() { $page.off(scrollEvents); + if( callback ){ + callback(); + } }); return false; } diff --git a/scrollimate.min.js b/scrollimate.min.js index 1fd1218..4a8b654 100644 --- a/scrollimate.min.js +++ b/scrollimate.min.js @@ -1 +1 @@ -var scrollimate=function(t){var a={wp:0,prlx:!1,speed:1,saBgLay:[],saWinHi:"",mobileEnabled:!1,isMObile:!1,indexable:!0,transition_type:""},e=function(t){for(var a=window,e=t.split("."),n=e.pop(),s=0;s767?n():a.saBgLay.css("transform","translate3d(0, 0, 0)")},s=function(e){for(var s=0;s1&&(o=1,"center"===c[1]?l=-l/2*c[0]:l*=c[1]);var f=1;f=""===i.attr("data-sabglayer")?1:c[0];var d={saBg:e[s],tOfSet:r,winHi:a.saWinHi,spd:f,elHeight:l,left:"0px",flag:o};"translateX(-50%)"===i.css("transform")&&(d.left="-50%"),n(d)}};jQuery.expr[":"].focus=function(t){return t===document.activeElement&&(t.type||t.href)};var o={saTabsHashKeyListener:function(e){if(t(".tabscroll_activeNavi").find("a, button").is(":focus"))if("36"==(e=e||window.event).keyCode){var n=t("[data-tabscrollnavi]:first-child").find("a, button");n.length&&!n[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=n.attr("href"),n.focus()):n.trigger("click").focus())}else if("35"==e.keyCode){var s=t(t("[data-tabscrollnavi]")[t("[data-tabscrollnavi]").length-1]).find("a, button");s.length&&!s[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=s.attr("href"),s.focus()):s.trigger("click").focus())}else if("37"==e.keyCode){var o=t(".tabscroll_activeNavi").prev("[data-tabscrollnavi]").find("a, button");o.length&&!o[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=o.attr("href"),o.focus()):o.trigger("click").focus())}else if("39"==e.keyCode){var i=t(".tabscroll_activeNavi").next("[data-tabscrollnavi]").find("a, button");i.length&&!i[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=i.attr("href"),i.focus()):i.trigger("click").focus())}},saTabsPrepActiveElement:function(t){t.attr("aria-selected","true").attr("tabindex","0").addClass("this--active").parent().addClass("tabscroll_activeNavi")},saTabsPrepInactiveElement:function(t){t.attr("aria-selected","false").attr("tabindex","-1").removeClass("this--active").parent().removeClass("tabscroll_activeNavi")}},i=function(e){t(document).trigger("satabchanged");var n,s=function(a){for(var e=t("[data-tabscrollnavi]"),n=0;n767?(void 0===s&&(s="33%"),o.css("float","left"),o.css("padding-bottom",s),o.css("width",r+"%").removeClass("active"),t(o[0]).css("width",e+"%").addClass("active")):(o.css("width","100%"),o.css("height",0).css("padding-bottom",r+"%").removeClass("active"),t(o[0]).css("height",0).css("padding-bottom",e+"%").addClass("active")),void 0===n&&(n="click"),o.on(n,function(){t(window).width()>767?(o.css("width",r+"%").removeClass("active"),t(this).css("width",e+"%").addClass("active")):(o.css("width","100%"),o.css("height",0).css("padding-bottom",r+"%").removeClass("active"),t(this).css("height",0).css("padding-bottom",e+"%").addClass("active"))}),setTimeout(function(){o.css("transition","all 0.6s")},1e3)};o(),window.addEventListener("resize",function(){o()})};jQuery.fn.saAccordion=function(t,a,e){return r(this,t,a,e),this};jQuery.fn.saUnderline=function(){return scrollimate.saUnderline(t(this)),this};var l=function(a){var e,n="#ffffff",s="click",o=!1;void 0!==a?(e=a.target||t(".ripple"),n=a.color||"#ffffff",s=a.interaction||"click",o=a.noclass||!1):e=t(".ripple"),t("#scrollimate__ripplestyles").length||t('\x3c!--[if IE 9]>"),o=t(e).offset(),i=a.pageX-o.left,r=a.pageY-o.top;s.addClass("ripple-effect");var l=t(".ripple-effect");l.css("height",t(e).height()),l.css("width",t(e).height());var c=t(e).data("ripplecolor")||n;s.css({top:r-l.height()/2,left:i-l.width()/2,background:c}).appendTo(t(e)),window.setTimeout(function(){s.remove()},1500)},r=!1;"mouseover"===s?(e.on(s,function(t){!0===r&&(i(t,this),r=!1)}),e.on("mouseout",function(){r=!0})):e.on(s,function(t){i(t,this)})};jQuery.fn.saRipple=function(a){for(var e,n=0;ne||l>e||r<-e||l<-e?(r>12*e||l>12*e||r<12*-e||l<12*-e)&&a.css("transform","translate(0px, 0px"):a.css("transform","translate("+r+"px, "+l+"px")},p=function(a){a.addClass("scrollimate-springyelement"),t("#scrollimate__springyelementstyles").length||t('').appendTo(t("head"))},m=function(a,e){e=e||20,p(a),a.each(function(){var a=t(this);c(a),a.on("mouseenter",function(t){a.attr("data-springyx",t.pageX),a.attr("data-springyy",t.pageY)}),a.on("mousemove",function(t){d(t,a,e)}),a.on("touchmove",function(t){d(t,a,e,!0)}),a.on("mouseup, mouseout",function(){f(a)}),a.on("touchend",function(){f(a)})})};jQuery.fn.springyElement=function(a){return m(t(this),a),this};var u=function(e,n,s,o){void 0!==e&&e.each(function(){if(a.wp+a.saWinHi>t(this).offset().top){var e=t(this);setTimeout(function(){e.addClass(s)},o)}else n&&t(this).removeClass(s)})},h=function(e,n){var s=!1,o="this--nowinview",i=0;void 0!==n&&(s=n.repeat||s,o=n.classname||o,i=n.delay||i),a.wp=t(window).scrollTop(),u(e,s,o,i),t(window).scroll(function(){u(e,s,o,i)})};jQuery.fn.scrollstuff=function(t){return h(this,t),this};return{enableMobile:function(){a.mobileEnabled=!0},init:function(n){t(function(){if(a.saWinHi="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,a.wp=t(window).scrollTop(),"[object Array]"==Object.prototype.toString.call(n)){console.log("Classic Init Method classically calling the following Methods: ");for(var o=0;o").text(e+" "))})}},springyElement:m}}(jQuery); \ No newline at end of file +var scrollimate=function(t){var a={wp:0,prlx:!1,speed:1,saBgLay:[],saWinHi:"",mobileEnabled:!1,isMObile:!1,indexable:!0,transition_type:""},e=function(t){for(var a=window,e=t.split("."),n=e.pop(),s=0;s767?n():a.saBgLay.css("transform","translate3d(0, 0, 0)")},s=function(e){for(var s=0;s1&&(o=1,"center"===c[1]?l=-l/2*c[0]:l*=c[1]);var f=1;f=""===i.attr("data-sabglayer")?1:c[0];var d={saBg:e[s],tOfSet:r,winHi:a.saWinHi,spd:f,elHeight:l,left:"0px",flag:o};"translateX(-50%)"===i.css("transform")&&(d.left="-50%"),n(d)}};jQuery.expr[":"].focus=function(t){return t===document.activeElement&&(t.type||t.href)};var o={saTabsHashKeyListener:function(e){if(t(".tabscroll_activeNavi").find("a, button").is(":focus"))if("36"==(e=e||window.event).keyCode){var n=t("[data-tabscrollnavi]:first-child").find("a, button");n.length&&!n[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=n.attr("href"),n.focus()):n.trigger("click").focus())}else if("35"==e.keyCode){var s=t(t("[data-tabscrollnavi]")[t("[data-tabscrollnavi]").length-1]).find("a, button");s.length&&!s[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=s.attr("href"),s.focus()):s.trigger("click").focus())}else if("37"==e.keyCode){var o=t(".tabscroll_activeNavi").prev("[data-tabscrollnavi]").find("a, button");o.length&&!o[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=o.attr("href"),o.focus()):o.trigger("click").focus())}else if("39"==e.keyCode){var i=t(".tabscroll_activeNavi").next("[data-tabscrollnavi]").find("a, button");i.length&&!i[0].hasAttribute("data-saexclude")&&(a.indexable?(window.location.hash=i.attr("href"),i.focus()):i.trigger("click").focus())}},saTabsPrepActiveElement:function(t){t.attr("aria-selected","true").attr("tabindex","0").addClass("this--active").parent().addClass("tabscroll_activeNavi")},saTabsPrepInactiveElement:function(t){t.attr("aria-selected","false").attr("tabindex","-1").removeClass("this--active").parent().removeClass("tabscroll_activeNavi")}},i=function(e){t(document).trigger("satabchanged");var n,s=function(a){for(var e=t("[data-tabscrollnavi]"),n=0;n767?(void 0===s&&(s="33%"),o.css("float","left"),o.css("padding-bottom",s),o.css("width",r+"%").removeClass("active"),t(o[0]).css("width",e+"%").addClass("active")):(o.css("width","100%"),o.css("height",0).css("padding-bottom",r+"%").removeClass("active"),t(o[0]).css("height",0).css("padding-bottom",e+"%").addClass("active")),void 0===n&&(n="click"),o.on(n,function(){t(window).width()>767?(o.css("width",r+"%").removeClass("active"),t(this).css("width",e+"%").addClass("active")):(o.css("width","100%"),o.css("height",0).css("padding-bottom",r+"%").removeClass("active"),t(this).css("height",0).css("padding-bottom",e+"%").addClass("active"))}),setTimeout(function(){o.css("transition","all 0.6s")},1e3)};o(),window.addEventListener("resize",function(){o()})};jQuery.fn.saAccordion=function(t,a,e){return r(this,t,a,e),this};jQuery.fn.saUnderline=function(){return scrollimate.saUnderline(t(this)),this};var l=function(a){var e,n="#ffffff",s="click",o=!1;void 0!==a?(e=a.target||t(".ripple"),n=a.color||"#ffffff",s=a.interaction||"click",o=a.noclass||!1):e=t(".ripple"),t("#scrollimate__ripplestyles").length||t('\x3c!--[if IE 9]>"),o=t(e).offset(),i=a.pageX-o.left,r=a.pageY-o.top;s.addClass("ripple-effect");var l=t(".ripple-effect");l.css("height",t(e).height()),l.css("width",t(e).height());var c=t(e).data("ripplecolor")||n;s.css({top:r-l.height()/2,left:i-l.width()/2,background:c}).appendTo(t(e)),window.setTimeout(function(){s.remove()},1500)},r=!1;"mouseover"===s?(e.on(s,function(t){!0===r&&(i(t,this),r=!1)}),e.on("mouseout",function(){r=!0})):e.on(s,function(t){i(t,this)})};jQuery.fn.saRipple=function(a){for(var e,n=0;ne||l>e||r<-e||l<-e?(r>12*e||l>12*e||r<12*-e||l<12*-e)&&a.css("transform","translate(0px, 0px"):a.css("transform","translate("+r+"px, "+l+"px")},p=function(a){a.addClass("scrollimate-springyelement"),t("#scrollimate__springyelementstyles").length||t('').appendTo(t("head"))},m=function(a,e){e=e||20,p(a),a.each(function(){var a=t(this);c(a),a.on("mouseenter",function(t){a.attr("data-springyx",t.pageX),a.attr("data-springyy",t.pageY)}),a.on("mousemove",function(t){d(t,a,e)}),a.on("touchmove",function(t){d(t,a,e,!0)}),a.on("mouseup, mouseout",function(){f(a)}),a.on("touchend",function(){f(a)})})};jQuery.fn.springyElement=function(a){return m(t(this),a),this};var u=function(e,n,s,o){void 0!==e&&e.each(function(){if(a.wp+a.saWinHi>t(this).offset().top){var e=t(this);setTimeout(function(){e.addClass(s)},o)}else n&&t(this).removeClass(s)})},h=function(e,n){var s=!1,o="this--nowinview",i=0;void 0!==n&&(s=n.repeat||s,o=n.classname||o,i=n.delay||i),a.wp=t(window).scrollTop(),u(e,s,o,i),t(window).scroll(function(){u(e,s,o,i)})};jQuery.fn.scrollstuff=function(t){return h(this,t),this};return{enableMobile:function(){a.mobileEnabled=!0},init:function(n){t(function(){if(a.saWinHi="innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight,a.wp=t(window).scrollTop(),"[object Array]"==Object.prototype.toString.call(n)){console.log("Classic Init Method classically calling the following Methods: ");for(var o=0;o").text(e+" "))})}},springyElement:m}}(jQuery);