jQuery插件animateSlide制作多點(diǎn)滑動(dòng)幻燈片
首頁banner的酷炫效果多來自全屏大圖的幻燈片動(dòng)畫,下面提供一種完美兼容的jquery動(dòng)畫特效:全新jquery多點(diǎn)滑動(dòng)幻燈片——全屏動(dòng)畫animateSlide(代碼完全原創(chuàng))。
直接上代碼,把html、css和jquery代碼copy到頁面上即可呈現(xiàn)完美畫面。
html代碼如下:
<div class="animateSlide">
<div class="animateSlideImgWrap">
<div class="animateSlideImgBox present">
<p class="text1">親,這是第一行標(biāo)題</p>
<p class="text2">AAAAAAAAAAAAAAAAAAAAA</p>
<!--<img class="img" alt="" src="img/1.png" />-->
<div class="img" style="width: 500px; height: 390px; background: #ffaeae; opacity: 0.6;"></div><!-- 實(shí)際項(xiàng)目中用上面注釋的半透明png圖片,目前臨時(shí)用div代替圖片 -->
</div>
<div class="animateSlideImgBox">
<p class="text1">親,這是一行宣傳語</p>
<p class="text2">BBBBBBBBBBBBBBBBBBBBB</p>
<!--<img class="img" alt="" src="img/2.png" />-->
<div class="img" style="width: 500px; height: 390px; background: #aeffb2; opacity: 0.6;"></div><!-- 實(shí)際項(xiàng)目中用上面注釋的半透明png圖片,目前臨時(shí)用div代替圖片 -->
</div>
<div class="animateSlideImgBox">
<p class="text1">親,這是一個(gè)奇跡啊</p>
<p class="text2">CCCCCCCCCCCCCCCCCCCCC</p>
<!--<img class="img" alt="" src="img/3.png" />-->
<div class="img" style="width: 500px; height: 390px; background: #aebdff; opacity: 0.6;"></div><!-- 實(shí)際項(xiàng)目中用上面注釋的半透明png圖片,目前臨時(shí)用div代替圖片 -->
</div>
</div>
<div class="animateSlideBtnL"><</div>
<div class="animateSlideBtnR"><</div>
</div>
css代碼如下:
.animateSlide {width: 100%; height: 390px; position: relative; background: #f5f5f5;}
.animateSlideImgWrap {width: 100%; height: 390px; position: absolute; z-index: 1; overflow: hidden;}
.animateSlideImgWrap .present {display: block;}
.animateSlideImgBox {width: 100%; height: 390px; position: absolute; z-index: 1; display: none;}
.animateSlideImgBox .text1 {font-family: Microsoft YaHei; font-size: 36px; line-height: 1.2em; color: #384cd0; position: absolute; top: 120px; z-index: 3; white-space: nowrap;}
.animateSlideImgBox .text2 {font-family: Microsoft YaHei; font-size: 26px; line-height: 1.2em; color: orange; position: absolute; top: 200px; z-index: 3; white-space: nowrap;}
.animateSlideImgBox .img {position: absolute; left: 470px; top: 0; z-index: 2;}
.animateSlideBtnL,
.animateSlideBtnR {
width: 30px; height: 60px; line-height: 60px; font-size: 20px; font-weight: 700; text-align: center; background: #ddd;
position: absolute; left: 30px; top: 150px; z-index: 6; cursor: pointer; display: none;
}
.animateSlideBtnR {left: auto; right: 20px;}
jquery代碼如下:
(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"))) {
//當(dāng)前幀動(dòng)畫
_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);
//下一幀動(dòng)畫
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
});
});
- jQuery中animate的幾種用法與注意事項(xiàng)
- jQuery animate easing使用方法圖文詳解
- jQuery中使用animate自定義動(dòng)畫的方法
- 深入理解jquery自定義動(dòng)畫animate()
- 分享有關(guān)jQuery中animate、slide、fade等動(dòng)畫的連續(xù)觸發(fā)、滯后反復(fù)執(zhí)行的bug
- 基于jquery animate操作css樣式屬性小結(jié)
- jQuery中animate動(dòng)畫第二次點(diǎn)擊事件沒反應(yīng)
- jQuery的animate函數(shù)實(shí)現(xiàn)圖文切換動(dòng)畫效果
- js實(shí)現(xiàn)類似jquery里animate動(dòng)畫效果的方法
- jquery使用animate方法實(shí)現(xiàn)控制元素移動(dòng)
- jQuery實(shí)現(xiàn)立體式數(shù)字動(dòng)態(tài)增加(animate方法)
相關(guān)文章
jQuery+PHP+Mysql實(shí)現(xiàn)抽獎(jiǎng)程序
這篇文章主要為大家詳細(xì)介紹了jQuery+PHP+Mysql實(shí)現(xiàn)抽獎(jiǎng)程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
jQuery滾動(dòng)條美化插件nicescroll簡(jiǎn)單用法示例
這篇文章主要介紹了jQuery滾動(dòng)條美化插件nicescroll簡(jiǎn)單用法,結(jié)合實(shí)例形式簡(jiǎn)單分析了jQuery滾動(dòng)條美化插件jquery.nicescroll.js的引入與使用技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2018-04-04
jQuery根據(jù)緯度經(jīng)度查看地圖處理程序
jQuery根據(jù)緯度經(jīng)度查看地圖處理程序如下在這里要注意js的引入順序,有需求的朋友可以參考下哈希望對(duì)你有所幫助2013-05-05
使用jquery動(dòng)態(tài)加載js文件的方法
這篇文章主要介紹了使用jquery動(dòng)態(tài)加載js文件的方法,需要的朋友可以參考下2014-12-12
基于jquery的多彩百分比 動(dòng)態(tài)進(jìn)度條 投票效果顯示效果實(shí)現(xiàn)代碼
基于jquery的多彩百分比 動(dòng)態(tài)進(jìn)度條 投票效果顯示效果實(shí)現(xiàn)代碼,學(xué)習(xí)jquery的朋友可以參考下。2011-08-08

