UNPKG

slideheader

Version:

A JavaScript plugin to display or hide headerbar with a sliding motion

1 lines 6.41 kB
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(global){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),_jquery="undefined"!=typeof window?window.$:"undefined"!=typeof global?global.$:null,_jquery2=_interopRequireDefault(_jquery),SlideHeader=function(){function SlideHeader(element,options){_classCallCheck(this,SlideHeader),this.element=element,this.$element=_jquery2["default"](element),this.methodType="",this.config={},this.options=options,this.slideFlag="up",this.defaults={headerBarHeight:this.$element.height(),headerBarWidth:"100%",header2SelectorName:".cb-header2",headerClone:!1,fullscreenView:!1,zIndex:9999,boxShadow:"none",opacity:1,slidePoint:0,slideDownDuration:"normal",slideUpDuration:"normal",slideDownEasing:"swing",slideUpEasing:"swing",slideDownCallback:function(){},slideUpCallback:function(){},headroom:!1}}return _createClass(SlideHeader,[{key:"slide",value:function(slideFlag,top,arg,css){var _this=this;this.slideFlag="up"===slideFlag?"down":"up",window.setTimeout(function(){_this.$element.stop().animate({top:top},_this.config["slide"+arg+"Speed"],_this.config["slide"+arg+"Easing"],_this.config["slide"+arg+"Callback"]).css(css)},200)}},{key:"slideHeader",value:function(){var _this2=this,w=_jquery2["default"](window),top1="slideDown"===this.methodType?0:"-"+this.config.headerBarHeight+"px",top2="slideDown"===this.methodType?"-"+this.config.headerBarHeight+"px":0,arg1="slideDown"===this.methodType?"Down":"Up",arg2="slideDown"===this.methodType?"Up":"Down",style1={"box-shadow":this.config.boxShadow,transition:"box-shadow .9s linear"},style2={"box-shadow":"none"},css1="slideDown"===this.methodType?style1:style2,css2="slideDown"===this.methodType?style2:style1,scrollStartPosition=0,scrollCurrentPosition=0;w.on("scroll",function(){if("slideUp"===_this2.methodType&&_this2.config.headroom===!0){if(scrollCurrentPosition=w.scrollTop(),scrollCurrentPosition>scrollStartPosition&&scrollCurrentPosition>_this2.config.slidePoint){if("up"===_this2.slideFlag)return _this2.slide(_this2.slideFlag,top1,arg1,css1)}else if("down"===_this2.slideFlag)return _this2.slide(_this2.slideFlag,top2,arg2,css2);scrollStartPosition=scrollCurrentPosition}else if(w.scrollTop()>_this2.config.slidePoint){if("up"===_this2.slideFlag)return _this2.slide(_this2.slideFlag,top1,arg1,css1)}else if("down"===_this2.slideFlag)return _this2.slide(_this2.slideFlag,top2,arg2,css2);return!1})}},{key:"setStyle",value:function(){var top="slideDown"===this.methodType?"-"+this.config.headerBarHeight+"px":0;this.$element.css({top:top,visibility:"visible",opacity:this.config.opacity,width:this.config.width,zIndex:this.config.zIndex})}},{key:"cloneHeader",value:function(){var clone=this.$element.clone(!0);clone.insertAfter(this.$element).removeClass("cb-header").addClass("cb-header1").css({"z-index":1e4})}},{key:"changeHeaderHeight",value:function(){var headerBarHeight=this.$element.height(),header2=_jquery2["default"](this.config.header2SelectorName),headerHeight=headerBarHeight+header2.height(),windowHeight=_jquery2["default"](window).height(),padding="";windowHeight>headerHeight?(padding=this.config.headerClone===!0?(windowHeight-headerHeight)/2:(windowHeight-headerHeight+headerBarHeight)/2,this.config.slidePoint=windowHeight,header2.css({"padding-top":padding+"px","padding-bottom":padding+"px"})):this.config.slidePoint=this.config.headerClone===!0?headerHeight:headerHeight-headerBarHeight}},{key:"init",value:function(){var type=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.methodType=type,this.config=_jquery2["default"].extend({},this.defaults,this.options),this.config.headerClone===!0&&this.cloneHeader(),this.setStyle(),this.config.fullscreenView===!0&&this.changeHeaderHeight(),this.slideHeader(),this}}]),SlideHeader}();exports["default"]=SlideHeader}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(require,module){(function(global){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_jquery="undefined"!=typeof window?window.$:"undefined"!=typeof global?global.$:null,_jquery2=_interopRequireDefault(_jquery),_SlideHeader=require("SlideHeader"),_SlideHeader2=_interopRequireDefault(_SlideHeader);!function(factory){"object"===("undefined"==typeof module?"undefined":_typeof(module))&&"object"===_typeof(module.exports)?module.exports=factory("undefined"!=typeof window?window.$:"undefined"!=typeof global?global.$:null):factory(_jquery2["default"])}(function($){$.extend($.fn,{cbSlideDownHeader:function(options){var _this=this;return this.each(function(){return new _SlideHeader2["default"](_this,options).init("slideDown")})},cbSlideUpHeader:function(options){var _this2=this;return this.each(function(){return new _SlideHeader2["default"](_this2,options).init("slideUp")})}})})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{SlideHeader:1}]},{},[2]);