- ;(function ($) {
- $.fn.cubeSlider = function(options){
- $.fn.cubeSlider.defaults = {
- element:"li",
- wrap:"ol",
- auto:true,
- styles:[
- {width:120, height:175, top:71, left:134, zIndex:1},
- {width:130, height:189, top:61, left:0, zIndex:2},
- {width:170, height:247, top:37, left:110, zIndex:3},
- {width:220, height:320, top:0, left:262, zIndex:4},
- {width:170, height:247, top:37, left:468, zIndex:3},
- {width:130, height:189, top:61, left:620, zIndex:2},
- {width:120, height:175, top:71, left:496, zIndex:1},
- {width:120, height:175, top:71, left:262, zIndex:0}
- ],
- "btnPrev":"#prev",
- "btnNext":"#next",
- "speed":400,
- "interval":3000
- }
- var opts = $.extend({},$.fn.cubeSlider.defaults,options || {});
- //
- return this.each(function(){
- var $this = $(this);
- var oWrap = $this.find(opts.wrap);
- var tags = oWrap.find(opts.element);
- var prev = $(opts.btnPrev);
- var next = $(opts.btnNext);
- var timer = null;
- //初始化显示
- render();
- //点击按钮切换
- prev.click(function(){
- oWrap.find(opts.element).eq(0).appendTo(oWrap);
- render();
- return false;
- });
- next.click(function(){
- oWrap.find(opts.element).eq(-1).prependTo(oWrap);
- render();
- return false;
- });
- //判断是否自动
- if(opts.auto){
- clearInterval(timer);
- timer = setInterval(move,opts.interval);
- }
- //鼠标移动上面停止运动
- $this.on({
- "mouseenter":function(){
- clearInterval(timer);
- },
- "mouseleave":function(){
- timer = setInterval(move,opts.interval);
- }
- });
- //轮播
- function move(){
- prev.trigger("click");
- }
- //渲染
- function render(){
- tags = $this.find(opts.element);
- tags.each(function(i,el){
- $(el).animate({
- "width":opts.styles[i].width + "px",
- "height":opts.styles[i].height + "px",
- "top":opts.styles[i].top + "px",
- "left":opts.styles[i].left + "px",
- "z-index":opts.styles[i].zIndex
- },opts.speed);
- });
- };
- });
- }
- })(jQuery);
- //该片段来自于http://www.codesnippet.cn/detail/041220137710.html
来源: http://www.codesnippet.cn/detail/041220137710.html