javascript - Using fadeIn / fadeOut with Scroll Up For Menu -
i'm using jquery script "scroll menu" david simpson, (github link) , trying uses fadein
, fadeout
, when scroll fades out, , when scroll nav fade in. can't seem figure out add it. better add easing event nav div (in case #top
) or fadein
within script?
js
;(function ( $, window, document, undefined ) { var pluginname = 'scrollupmenu'; var defaults = { waittime: 100, transitiontime: 550, menucss: { 'position': 'fixed', 'top': '0'}, showdelta: 0 }; var lastscrolltop = 0; var $header; var timer; var pixelsfromthetop; // actual plugin constructor function plugin ( element, options ) { this.element = element; this.settings = $.extend( {}, defaults, options ); this._defaults = defaults; this._name = pluginname; this.init(); } plugin.prototype = { init: function () { var self = this; $header = $(this.element); $header.css(self.settings.menucss); pixelsfromthetop = $header.height(); // $header.next().css({ 'margin-top': pixelsfromthetop }); $(window).bind('scroll',function () { cleartimeout(timer); timer = settimeout(function() { self.refresh(self.settings); }, self.settings.waittime ); }); }, refresh: function (settings) { // stopped scrolling, stuff... var scrolltop = $(window).scrolltop(); var change = lastscrolltop - scrolltop; if (scrolltop > lastscrolltop && scrolltop > pixelsfromthetop){ // ensure header doesnt disappear // downscroll $header.slideup(settings.transitiontime); } else { // upscroll if ( change > settings.showdelta ) { $header.slidedown(settings.transitiontime); } } lastscrolltop = scrolltop; } }; $.fn[ pluginname ] = function ( options ) { return this.each(function() { if ( !$.data( this, 'plugin_' + pluginname ) ) { $.data( this, 'plugin_' + pluginname, new plugin( this, options ) ); } }); }; })( jquery, window, document );
html
$(function() { $('#top').scrollupmenu({'transitiontime': 100}); });
jsfiddle https://jsfiddle.net/09qxdx43/2/
solved! fadein/fadeout instead of slideup
;(function ( $, window, document, undefined ) { var pluginname = "scrollupmenu"; var defaults = { waittime: 20, transitiontime: 300, menucss: { 'position': 'fixed', 'top': '0'} }; var lastscrolltop = 0; var $header; var timer; var pixelsfromthetop; // actual plugin constructor function plugin ( element, options ) { this.element = element; this.settings = $.extend( {}, defaults, options ); this._defaults = defaults; this._name = pluginname; this.init(); } plugin.prototype = { init: function () { var self = this; $header = $(this.element); $header.css(self.settings.menucss); pixelsfromthetop = $header.height(); $header.next().css({ 'margin-top': pixelsfromthetop }); $(window).bind('scroll',function () { cleartimeout(timer); timer = settimeout(function() { self.refresh(self.settings) }, self.settings.waittime ); }); }, refresh: function (settings) { // stopped scrolling, stuff... var scrolltop = $(window).scrolltop(); if (scrolltop > lastscrolltop && scrolltop > pixelsfromthetop){ // ensure header doesnt disappear // downscroll $header.fadeout(settings.transitiontime); } else { // upscroll $header.fadein(settings.transitiontime); } lastscrolltop = scrolltop; } }; $.fn[ pluginname ] = function ( options ) { return this.each(function() { if ( !$.data( this, "plugin_" + pluginname ) ) { $.data( this, "plugin_" + pluginname, new plugin( this, options ) ); } }); }; })( jquery, window, document );
Comments
Post a Comment