Skip to content

Instantly share code, notes, and snippets.

@titanew
Last active December 18, 2015 04:39
Show Gist options
  • Save titanew/5726855 to your computer and use it in GitHub Desktop.
Save titanew/5726855 to your computer and use it in GitHub Desktop.
小切换和小滚动。
(function($) {
//选项卡
$.fn.tab = function(options) {
var defaults = {
classname: "news-content",
speed: "100",
evt: "mouseover"
};
var opts = $.extend({}, defaults, options);
this.each(function() {
var _this = $(this);
var _child = $(this).children("li");
var _target = $("." + opts.classname).find("ul");
_child.bind(opts.evt, function() {
var index = _child.index($(this));
$(this).siblings().removeClass("selected").end().addClass("selected");
if (_target) {
_target.stop(true, true).slideUp(opts.speed);
_target.eq(index).slideDown(opts.speed);
};
});
});
};
// 滚动
$.fn.scroll = function(options) {
var defaults = {
ease: "easeInOutExpo",
left: "-186",
timeout: "2000"
}
var opts = $.extend({}, defaults, options)
return this.each(function() {
var _this = $(this);
var _clone = _this.find("li");
var _length = _this.find("li").size();
var num = 0;
var _animate = function() {
_this.css({
left: "0"
});
_this.animate({
left: opts.left
}, 500, opts.ease);
num++;
num = num > _length ? 1 : num;
_clone.eq(num - 1).appendTo(_this);
}
var timer = setInterval(_animate, opts.timeout);
_this.bind("mouseover", function() {
clearInterval(timer);
});
_this.bind("mouseout", function() {
timer = setInterval(_animate, opts.timeout);
});
});
};
})(jQuery)
//usage:
$(".news-tab").tab({
classname: "news-content",
speed: "100",
evt: "mouseover"
})
//usage:
$(".product-list-scroll").scroll({
ease: "easeInOutExpo",
left: "-186",
timeout: "2000"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment