Created
December 23, 2011 00:55
-
-
Save SET001/1512578 to your computer and use it in GitHub Desktop.
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
$.fn.slider = function(config){ | |
var settings = { | |
next: $('.btn_next'), | |
prev: $('.btn_next'), | |
c_visible_items: null, | |
item_width: null, | |
}; | |
if (config) $.extend(settings,config); | |
var is_clickable = true; | |
var that = this; | |
var first_child = $(this.children()[0]); | |
if(settings.item_width === null){ | |
settings.item_width | |
= parseInt(first_child.css('margin-left')) | |
+ parseInt(first_child.css('margin-right')) | |
+ first_child[0].clientWidth; | |
} | |
var slider_width = settings.item_width * this.children().length; | |
if (settings.c_visible_items === null){ | |
settings.c_visible_items = Math.round(this.parent().parent().parent()[0].clientWidth / settings.item_width); | |
} | |
this.parent().parent().css('width', slider_width); | |
settings.next.click(function(){ | |
slide(-1); | |
return false; | |
}); | |
settings.prev.click(function(){ | |
slide(1); | |
return false; | |
}); | |
var slide = function(revers){ | |
var left = parseInt(that.css('margin-left')) + (settings.item_width * revers); | |
if (is_clickable && left<=0 && left>=settings.c_visible_items*settings.item_width - slider_width){ | |
left += 'px'; | |
is_clickable = false; | |
that.animate({'margin-left': left}, 300, 'linear', function(){is_clickable=true;}); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment