这只是一个简易的旋转木马插件,理解其中的原理比较重要
;(function ($) {
$.fn.extend({
transiton:function (json) {
json = $.extend([
{
width: 400,
top: 20,
left: 50,
opacity: 0.2,
zIndex: 2
},
{
width: 600,
top: 70,
left: 0,
opacity: 0.8,
zIndex: 3
},
{
width: 800,
top: 100,
left: 200,
opacity: 1,
zIndex: 4
},
{
width: 600,
top: 70,
left: 600,
opactity: 0.8,
zIndex: 3
},
{
width: 400,
top: 20,
left: 750,
opacity: 0.2,
zIndex: 2
}
],json);
var $lis = this.find('ul>li');
$lis.each(function (i, e) {
$(e).stop()
.animate({
'width': json[i].width,
'top': json[i].top,
'left': json[i].left,
'opacity': json[i].opacity,
'zIndex': json[i].zIndex
}, 1000);
});
this.on('mouseenter', function () {
this.children().children('div.arrow').stop().animate({opacity:1},500);
});
this.on('mouseleave', function () {
this.children().children('div.arrow').stop().animate({opacity:0},500);
});
this.find('div>a.prev').on('click', function () {
json.push(json.shift());
$lis.each(function (i, e) {
$(e).stop()
.animate({
'width': json[i].width,
'top': json[i].top,
'left': json[i].left,
'opacity': json[i].opacity,
'zIndex': json[i].zIndex
}, 500);
});
});
this.find('div>a.next').on('click', function () {
json.unshift(json.pop());
$lis.each(function (i, e) {
$(e).stop()
.animate({
'width': json[i].width,
'top': json[i].top,
'left': json[i].left,
'opacity': json[i].opacity,
'zIndex': json[i].zIndex
}, 500);
});
});
}
});
})(jQuery);