//Usage $(element).contentslider({ direction: 'right', });
Created
June 5, 2013 06:29
-
-
Save praveensewak/5711989 to your computer and use it in GitHub Desktop.
jQuery Content Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.contentslider { | |
display: block; | |
position: absolute; | |
position: fixed; | |
top: 0; | |
right: 0; | |
height: 100%; | |
z-index: 900000; | |
width: 600px; | |
padding: 20px; | |
background-color: #333; | |
color: #fff; | |
-webkit-box-shadow: 0px 0px 7px 5px rgba(0, 0, 0, 0.4); | |
-moz-shadow: 0px 0px 7px 5px rgba(0, 0, 0, 0.4); | |
box-shadow: 0px 0px 7px 5px rgba(0, 0, 0, 0.4); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery Content Slider | |
// A jQuery plugin to slide in a content area within a page | |
// version 1.0, June 5th, 2013 | |
// by Praveen Sewak https://github.com/praveensewak | |
; (function ($) { | |
$.contentslider = function (element, options) { | |
var defaults = { | |
speed: 200, | |
direction: 'right', | |
} | |
var slider = this, | |
_sliding = false; | |
slider.settings = {} | |
var $element = $(element), | |
$elementWidth = 0, | |
element = element; | |
// init | |
slider.init = function () { | |
slider.settings = $.extend({}, defaults, options); | |
$element.addClass('contentslider'); | |
$elementWidth = $element.outerWidth(true); | |
$element.css(slider.settings.direction, '-' + $elementWidth + 'px'); | |
$element.hide(); | |
} | |
// show | |
slider.show = function () { | |
var animateIn = {}; | |
if ($element.is(':visible') || _sliding) return; | |
_sliding = true; | |
switch (slider.settings.direction) { | |
case 'left': | |
animateIn['left'] = '0'; | |
break; | |
default: | |
animateIn['right'] = '0'; | |
break; | |
} | |
$element.show().animate(animateIn, slider.settings.speed, function () { | |
_sliding = false; | |
}); | |
} | |
// hide | |
slider.hide = function () { | |
var animateOut = {}; | |
if ($element.is(':hidden') || _sliding) return; | |
_sliding = true; | |
switch (slider.settings.direction) { | |
case 'left': | |
animateOut['left'] = '-' + $elementWidth; | |
break; | |
default: | |
animateOut['right'] = '-' + $elementWidth; | |
break; | |
} | |
$element.animate(animateOut, slider.settings.speed, function () { | |
$element.hide(); | |
_sliding = false; | |
}); | |
} | |
var foo_private_method = function () { | |
// code goes here | |
} | |
slider.init(); | |
// Events | |
$element.click(function (e) { | |
e.stopPropagation(); | |
}); | |
} | |
$.fn.contentslider = function (options) { | |
return this.each(function () { | |
if (undefined == $(this).data('contentslider')) { | |
var slider = new $.contentslider(this, options); | |
$(this).data('contentslider', slider); | |
} | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment