Repository: ahmedrad/sliiide Branch: master Commit: 3b24e97d46d4 Files: 4 Total size: 16.3 KB Directory structure: gitextract_isg47xg9/ ├── LICENSE ├── README.md ├── bower.json └── sliiide.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Ahmed Radwan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ Checkout the demo [here](http://ahmedrad.github.io/sliiide/). First things first, this plugin is currently in Beta, please feel free to take if for a test ride into the wild and send back any feedback or bugs you might encounter. I created this plugin out of frustration with all the slider jQuery plugins out there that just weren’t doing it for me. Enjoy :) ##What to use this for? You have a div (probably a nav menu or a side bar) that you want to animate with a sliding effect from outside the viewport to inside the viewport. You want to have complete control over the distance this div slides but you don’t want to worry about how to position it or how to stretch it to match the screen’s dimensions. You also don’t wanna bother with how the animation affects the rest of the page, how to deal with scrolling and the logic behind activating and deactivating the menu. ##Any Dependencies? The plugin is built on jQuery 2.1.0 but could potentially work with older and newer versions, give it a shot and let me know how it goes if you run into any problems. Otherwise, there’s no CSS file or anything else needed. This plugin manipulates inline styles for the element you're using as a slide menu and some manipulation to the body element. If you're also doing a lot of inline style manipulation you might run into conflicts. ####this plugin officially supports chrome, firefox, safari, IE 10/11 and Edge ##How to use it? 1- Download the sliiide js file (or the minified version) from the github repo, include the js file before the body end tag and make sure jQuery is included before it. Or just use bower "bower install sliiide" 2- you’ll need a div (a nav menu or whatever you have in mind) and set its visibility to hidden. PLEASE MAKE SURE THIS DIV IS A DIRECT CHILD OF THE BODY ELEMENT. You also need a settings object. ``` var settings = { toggle: "#sliiider-toggle", // the selector for the menu toggle, whatever clickable element you want to activate or deactivate the menu. A click listener will be added to this element. exit_selector: ".slider-exit", // the selector for an exit button in the div if needed, when the exit element is clicked the menu will deactivate, suitable for an exit element inside the nav menu or the side bar animation_duration: "0.5s", //how long it takes to slide the menu place: "left", //where is the menu sliding from, possible options are (left | right | top | bottom) animation_curve: "cubic-bezier(0.54, 0.01, 0.57, 1.03)", //animation curve for the sliding animation body_slide: true, //set it to true if you want to use the effect where the entire page slides and not just the div no_scroll: true, //set to true if you want the scrolling disabled while the menu is active auto_close: false //set to true if you want the slider to auto close everytime a child link of it is clicked }; $(‘#menu’).sliiide(settings); //initialize sliiide ``` 3- If you’re going to slide that div horizontally (from the right or left) then you need to style the width of the div yourself and sliiide will stretch the height for you to full window height. If you’re going to slide it vertically (from the top or the bottom) then you need to style the height and sliiide will stretch the width for you. the sliding effect will change to match whatever styling you added to the width (or height) of the element. 4- useful functions available for you: ``` var menu = $('.left-menu').sliiide({place: 'left', exit_selector: '.some-exit-selector', toggle: '#some-toggle-selector, no_scroll: true, body_slide: true'}); menu.activate(); //slides the menu open menu.deactivate(); //slides the menu closed menu.reset(); //removes all the css that sliiide added to any element ``` That’s it, you now should be good to go, feel free to report back any issues you encounter I’m happy to continue working on this. ================================================ FILE: bower.json ================================================ { "name": "sliiide", "main": "sliiide.min.js", "homepage": "https://github.com/ahmedrad/sliiide", "authors": [ "Ahmed Radwan " ], "description": "The Easiest Way to Create a Sliding Nav Menu with jQuery", "moduleType": [ "globals" ], "keywords": [ "jquery", "plugin", "slide", "slideout", "menu", "navigation", "offcanvas" ], "license": "MIT" } ================================================ FILE: sliiide.js ================================================ (function ($) { //get IE version if browser is IE var ie = (function detectIE() { var ua = window.navigator.userAgent; var msie = ua.indexOf('MSIE '); if (msie > 0) { return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); } var trident = ua.indexOf('Trident/'); if (trident > 0) { var rv = ua.indexOf('rv:'); return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); } var edge = ua.indexOf('Edge/'); if (edge > 0) { return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); } return false; })(); $.fn.sliiide = function(options) { var settings = $.extend({ toggle: "#sliiider-toggle", exit_selector: ".slider-exit", animation_duration: "0.5s", place: "right", animation_curve: "cubic-bezier(0.54, 0.01, 0.57, 1.03)", body_slide: true, no_scroll: false, auto_close: false }, options ); var newSize; var clicked = false; var $sliiider = $(this); var $toggle = $(settings.toggle); var $exit = $(settings.exit_selector); var $body = $('body'); var bodySlideDistance; var bodyResetProp = { transform: '', 'overflow-x': '', transition: '', position: '' }; var sliiiderResetProp = { transform: '', transition: '', width: '', height: '', left: '', top:'', bottom:'', right:'' }; var prepareProperties = { visibility: 'hidden', transition: 'transform ' + settings.animation_duration + ' ' + settings.animation_curve, position: 'fixed' }; var bodyChildrenProp = { transition: 'transform ' + settings.animation_duration + ' ' + settings.animation_curve }; var htmlProp = { 'overflow-x': 'hidden' }; var bodySlidePrepare = { position: 'relative', // to make overflow-x hidden work with mobile browsers 'overflow-x': 'hidden', }; var bodySlideProp = { setleft: function(distance) { this.left.activateAnimation.transform = 'translateX('+distance+'px)'; this.left.deactivateAnimation.transform = 'translateX(0px)'; }, setright: function(distance) { this.right.activateAnimation.transform = 'translateX(-'+distance+'px)'; this.right.deactivateAnimation.transform = 'translateX(0px)'; }, setbottom: function(distance) { this.bottom.activateAnimation.transform = 'translateY(-'+distance+'px)'; this.bottom.deactivateAnimation.transform = 'translateY(0px)'; }, settop: function(distance) { this.top.activateAnimation.transform = 'translateY('+distance+'px)'; this.top.deactivateAnimation.transform = 'translateY(0px)'; }, left: { activateAnimation: {transform:''}, deactivateAnimation: {transform: ''} }, right: { activateAnimation: {transform: ''}, deactivateAnimation: {transform: ''} }, top: { activateAnimation: {transform: ''}, deactivateAnimation: {transform: ''} }, bottom: { activateAnimation: {transform: ''}, deactivateAnimation: {transform: ''} } }; var Prop = { left: { properties: function() { var left = '-' + $sliiider.width() + 'px'; return {top: '0', left: left}; }, activateAnimation: {transform: 'translateX(100%)'}, deactivateAnimation: {transform: 'translateX(0)'}, size: function (wHeight, wWidth) { return {height: wHeight}; } }, right: { properties: function() { var right = '-' + $sliiider.width() + 'px'; return {top: '0', right: right}; }, activateAnimation: {transform: 'translateX(-100%)'}, deactivateAnimation: {transform: 'translateX(0)'}, size: function (wHeight, wWidth) { return {height: wHeight}; } }, top: { properties: function() { var top = '-' + $sliiider.height() + 'px'; return {left: '0', right:'0', top: top}; }, activateAnimation: {transform: 'translateY(100%)'}, deactivateAnimation: {transform: 'translateY(0)'}, size: function (wHeight, wWidth) { return {width: wWidth}; } }, bottom: { properties: function() { var bottom = '-' + $sliiider.height() + 'px'; return {left:0, right:0 , bottom: bottom}; }, activateAnimation: {transform: 'translateY(-100%)'}, deactivateAnimation: {transform: 'translateY(0)'}, size: function (wHeight, wWidth) { return {width: wWidth}; } } }; var prefixCSS = function(cssProp) { $.each(cssProp, function(k, v) { if(k === 'transition') { var trnsCSS = {}; var trnsProp = v.split(' ',1)[0]; var trnsAttr = v.split(' '); trnsAttr.shift(); trnsAttr = trnsAttr.join(' '); trnsCSS['-webkit-'+k] = '-webkit-' + trnsProp + ' ' + trnsAttr; trnsCSS['-ms-'+k] = '-ms-' + trnsProp + ' ' + trnsAttr; $.extend(cssProp, trnsCSS); } else if (k === 'transform') { var trnsfCSS = {}; trnsfCSS['-webkit-'+k] = v; trnsfCSS['-ms-'+k] = v; } }); return cssProp; }; var siiize = function() { var windowSize = {}; var scroll = getScrollBarWidth(); windowSize.height = $(window).height(); windowSize.width = $(window).width() + scroll; newSize = Prop[settings.place].size(windowSize.height, windowSize.width); $sliiider.css(newSize); $sliiider.css(prefixCSS(Prop[settings.place].properties())); setSlideDistance(); }; var setSlideDistance = function() { if(settings.body_slide) { if(settings.place === 'right' || settings.place === 'left') { bodySlideDistance = $sliiider.width(); } else { bodySlideDistance = $sliiider.height(); } bodySlideProp['set'+settings.place](bodySlideDistance); } }; var prepare = function() { $sliiider.css(prefixCSS(prepareProperties)); $sliiider.css(prefixCSS(Prop[settings.place].properties())); setSlideDistance(); }; var getScrollBarWidth = function() { var inner = document.createElement('p'); inner.style.width = "100%"; inner.style.height = "200px"; var outer = document.createElement('div'); outer.style.position = "absolute"; outer.style.top = "0px"; outer.style.left = "0px"; outer.style.visibility = "hidden"; outer.style.width = "200px"; outer.style.height = "150px"; outer.style.overflow = "hidden"; outer.appendChild (inner); document.body.appendChild (outer); var w1 = inner.offsetWidth; outer.style.overflow = 'scroll'; var w2 = inner.offsetWidth; if (w1 === w2) { w2 = outer.clientWidth; } document.body.removeChild (outer); return (w1 - w2); }; var activate = function() { siiize(); //sets the size of the slider menu and the distance the body will travel on sliding $sliiider.css('visibility','visible'); if(settings.body_slide) { $body.css(prefixCSS(bodySlidePrepare)); $('html').css(htmlProp); $body.children().css(prefixCSS(bodyChildrenProp)); $body.children().css(prefixCSS(bodySlideProp[settings.place].activateAnimation)); if((ie !== false) && (ie <= 11)) { $sliiider.css(prefixCSS(Prop[settings.place].activateAnimation)); } //dealing with the browser bug of inability to transform fixed elements var windowHeight = $(window).height(); var scrollTop = $(window).scrollTop(); var sliiiderHeight = $sliiider.height(); var sliiiderOffsetTop = $sliiider.offset().top; // if((sliiiderOffsetTop !== scrollTop) && settings.place !== "bottom" && !(ie && ie <= 11 && settings.place ==="top")) // { // $sliiider.css('top', scrollTop); // } // if(((sliiiderOffsetTop !== scrollTop + windowHeight) && (settings.place === "bottom"))) // { // $sliiider.css('top', scrollTop + windowHeight - sliiiderHeight).css('bottom',''); // } } else { $sliiider.css(prefixCSS(Prop[settings.place].activateAnimation)); } if(settings.no_scroll) { disable_scroll(); } clicked = true; }; var hideSlider = function(e) { $sliiider.css('visibility','hidden'); $body.css(bodyResetProp); $('html').css(bodyResetProp); $body.unbind('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', hideSlider); prepare(); }; function deactivate() { $body.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', hideSlider); if(settings.body_slide) { $body.children().css(prefixCSS(bodySlideProp[settings.place].deactivateAnimation)); if((ie !== false) && (ie <= 11)) {$sliiider.css(prefixCSS(Prop[settings.place].deactivateAnimation));} } else { $sliiider.css(prefixCSS(Prop[settings.place].deactivateAnimation)); } if(settings.no_scroll) { enable_scroll(); } clicked = false; } siiize(); prepare(); $(window).resize(siiize); $sliiider.resize(siiize); var handleToggle = function() { if (!clicked) {activate();} else {deactivate();} }; $toggle.click(handleToggle); if (settings.auto_close) { $sliiider.find('a').on('click', function() {deactivate();}); } $exit.on('click', function() {deactivate();}); var deleteProp = function() { $body.css(bodyResetProp); $sliiider.css(sliiiderResetProp); $(window).off('resize', siiize); $toggle.off('click', handleToggle); }; var menu = { reset: function(name) { $body.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', deleteProp); deactivate(); }, deactivate: function() {deactivate();}, activate: function() {activate();} }; return menu; }; //enable and disable scroll // left: 37, up: 38, right: 39, down: 40, // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36 var keys = {37: 1, 38: 1, 39: 1, 40: 1}; function preventDefault(e) { e = e || window.event; if (e.preventDefault) e.preventDefault(); e.returnValue = false; } function preventDefaultForScrollKeys(e) { if (keys[e.keyCode]) { preventDefault(e); return false; } } function disable_scroll() { if (window.addEventListener) // older FF window.addEventListener('DOMMouseScroll', preventDefault, false); window.onwheel = preventDefault; // modern standard window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE window.ontouchmove = preventDefault; // mobile document.onkeydown = preventDefaultForScrollKeys; } function enable_scroll() { if (window.removeEventListener) window.removeEventListener('DOMMouseScroll', preventDefault, false); window.onmousewheel = document.onmousewheel = null; window.onwheel = null; window.ontouchmove = null; document.onkeydown = null; } }(jQuery));