首页banner的酷炫效果多来自全屏大图的幻灯片动画,下面提供一种完美兼容的jquery动画特效:全新jquery多点滑动幻灯片——全屏动画animateSlide(代码完全原创)。
(function($) {
$.fn.animateSlide = function(options) {
var defaults = {
btnL: ".animateSlideBtnL",
btnR: ".animateSlideBtnR",
imgBox: ".animateSlideImgBox",
animateTime: 500,
delayTime: 5000,
density: 1
};
var opts = $.extend(defaults, options);
var widthWin = $(window).width();
$(window).resize(function() {
widthWin = $(window).width();
});
//
this.on("mouseenter", function() {
$(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeIn(400);
}).on("mouseleave", function() {
$(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeOut(400);
});
return this.each(function() {
var _this = $(this);
var _btnL = _this.find(opts.btnL);
var _btnR = _this.find(opts.btnR);
var _imgBox = _this.find(opts.imgBox);
var _imgBoxCur = _imgBox.filter(".present");
var _curText1 = _imgBoxCur.find(".text1"), _curText2 = _imgBoxCur.find(".text2"), _curImg = _imgBoxCur.find(".img");
var _imgBoxNext = null, _nextText1 = null, _nextText2 = null, _nextImg = null;
var index = _imgBox.index(_imgBoxCur) || 0;
var size = _imgBox.size();
var start = null;
index++;
if(index >= size) {
index = 0;
}
_imgBoxNext = _imgBox.eq(index);
_nextText1 = _imgBoxNext.find(".text1");
_nextText2 = _imgBoxNext.find(".text2");
_nextImg = _imgBoxNext.find(".img");
_imgBox.find(".text1, .text2, .img").css("left", widthWin);
_imgBoxCur.find(".text1, .text2").css("left", (widthWin - 980) / 2 + "px");
_imgBoxCur.find(".img").css("left", (widthWin - 980) / 2 + 470 + "px");
_btnR.on("click", function() {
animateSlideFn();
});
_btnL.on("click", function() {
animateSlideFn();
});
start = setTimeout(function() {
animateSlideFn();
start = setTimeout(arguments.callee, opts.delayTime);
}, opts.delayTime);
function animateSlideFn() {
if(!(_imgBoxCur.find(".text1, .text2, .img").is(":animated") || _imgBoxNext.find(".text1, .text2, .img").is(":animated"))) {
//当前帧动画
_curText1.animate({
left: parseInt(_curText1.css("left")) + 100
}, opts.animateTime * 0.6, function() {
_curText1.animate({
left: "-510px"
}, opts.animateTime);
});
setTimeout(function() {
_curText2.animate({
left: parseInt(_curText2.css("left")) + 100
}, opts.animateTime * 0.6, function() {
_curText2.animate({
left: "-510px"
}, opts.animateTime);
});
}, 200);
setTimeout(function() {
_curImg.animate({
left: parseInt(_curImg.css("left")) + 200
}, opts.animateTime * 0.6, function() {
_curImg.animate({
left: "-510px"
}, opts.animateTime, function() {
_imgBox.find(".text1, .text2, .img").css("left", widthWin);
_imgBoxCur.removeClass("present");
});
});
}, 400);
//下一帧动画
setTimeout(function() {
_imgBoxNext.addClass("present");
_nextText1.animate({
left: (widthWin - 980) / 2 - 100
}, opts.animateTime, function() {
_nextText1.animate({
left: (widthWin - 980) / 2
}, opts.animateTime * 0.6);
});
setTimeout(function() {
_nextText2.animate({
left: (widthWin - 980) / 2 - 100
}, opts.animateTime, function() {
_nextText2.animate({
left: (widthWin - 980) / 2
}, opts.animateTime * 0.6);
});
}, 200);
setTimeout(function() {
_nextImg.animate({
left: (widthWin - 980) / 2 + 370
}, opts.animateTime, function() {
_nextImg.animate({
left: (widthWin - 980) / 2 + 470
}, opts.animateTime * 0.6, function() {
index++;
if(index >= size) {
index = 0;
}
_imgBoxCur = _imgBox.filter(".present");
_imgBoxNext = _imgBox.eq(index);
_curText1 = _imgBoxCur.find(".text1");
_curText2 = _imgBoxCur.find(".text2");
_curImg = _imgBoxCur.find(".img");
_nextText1 = _imgBoxNext.find(".text1");
_nextText2 = _imgBoxNext.find(".text2");
_nextImg = _imgBoxNext.find(".img");
});
});
}, 400);
}, opts.density * 1200);
}
}
});
};
})(jQuery);
$(function() {
$(".animateSlide").animateSlide({
btnL: ".animateSlideBtnL",
btnR: ".animateSlideBtnR",
imgBox: ".animateSlideImgBox",
animateTime: 500,
delayTime: 6000,
density: 0.9
});
});