Skip to content

Instantly share code, notes, and snippets.

@abruzzihraig
Created November 10, 2014 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzihraig/511b9bf412b5d855150f to your computer and use it in GitHub Desktop.
Save abruzzihraig/511b9bf412b5d855150f to your computer and use it in GitHub Desktop.
一个简单封装的slider对象
function Slider(slider_class, animation_type, slider_width, page_counts) {
var _ = this;
_.slider_tag = $('.' + slider_class);
_.slider_content = _.slider_tag.find('.slider-content');
_.prev = _.slider_tag.find('.prev');
_.next = _.slider_tag.find('.next');
_.dots = _.slider_tag.find('.slider-dotted');
_.cursor = 0;
_.width = slider_width;
_.jump = function(dist_cursor) {
dist_cursor = (dist_cursor < 0) ? dist_cursor+page_counts : dist_cursor%page_counts;
var gap = dist_cursor - _.cursor;
var last_left = _.cursor*-_.width;
_.cursor = dist_cursor;
_.dots.removeClass('active').eq(dist_cursor).addClass('active');
_.slider_content.finish().velocity({
left: last_left-_.width*gap
}, 500, animation_type);
};
_.prev.click(function () {
_.jump(_.cursor-1)
});
_.next.click(function () {
_.jump(_.cursor+1)
});
_.dots.click(function() {
_.jump($(this).index());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment