Created
September 15, 2011 12:46
-
-
Save Radagaisus/1219146 to your computer and use it in GitHub Desktop.
Vertical Slideshow jQuery Plugin (prototype)
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
(function($) { | |
$.fn.vslide = function(options) { | |
var defaults = { | |
slide: '.slide', | |
slide_inner: '.slide-inner' | |
next: '.next', | |
prev: '.prev', | |
slideHeight: 640, | |
slideWidth: 700, | |
vertical: true, | |
animations: {}, | |
keyboard: false, | |
fixedFix: function() {}, | |
init: function() { | |
// Resize | |
// Resizing | |
$(window).resize(function() { | |
options.resizeWindow(); | |
}); | |
window.onorientationchange = function(){ | |
options.resizeWindow(); | |
} | |
options.resizeWindow(); | |
// Listen to Scroll & Animate | |
$(window).scroll(function(e) { | |
var slide = getCurrentSlide(); | |
$("body").data('slideNum', slide); | |
switch (slide) { | |
typeof options.animations[slide] "undefined" || options.animations[slide]() | |
} | |
// iOS fix for position fixed | |
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') { | |
fixedFix() | |
} | |
}); | |
options.keyboardNav() | |
$(options.prev).click(function() { | |
goto(currentSlide - 1); | |
}); | |
$(options.next).click(function() { | |
goto(currentSlide + 1); | |
}); | |
}, | |
resizeWindow: function() { | |
$(options.slide).css('height', ($(window).height() < 640 ? 640 : $(window).height())); | |
}, | |
goto: function(slide) { | |
$(document).scrollTop(slide * options.getSlideHeight() $(document).scrollTop()) | |
}, | |
getSlideHeight: function() { | |
return $(document).scrollTop() / _.max([options.slideHeight, $(window).height()]); | |
}, | |
currentSlide: function() { | |
var s = $(document).scrollTop() / _.max([options.slideHeight, $(window).height()]); | |
return s % 1 > 0.95 ? Math.floor(s) : Math.ceil(s); | |
}, | |
keyboardNav: function() { | |
if (! keyboard) return; | |
$(document).keyup(function(e) { | |
code = e.keyCode | |
if (code > 36 && code < 41 || code == 32) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
goto(currentSlide() + (code == 38 || code == 37 ? -1 : 1)); | |
} | |
}); | |
} | |
}; | |
var options = $.extend(defaults, options); | |
options.self = options; | |
return this.each(function() { | |
options.elem = $(this); | |
options.init(); | |
}); | |
}})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment