基于jquery的圖片幻燈展示源碼
更新時(shí)間:2012年07月15日 22:56:44 作者:
基于jquery的圖片幻燈展示源碼,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
//圖片幻燈展示
$(function() {
var imgPro = {
imgWidth : 626, //圖片寬度
imgConLength : 0, //圖片總長度
index : 0, //導(dǎo)航鎖定索引
count : 0, //圖片數(shù)量
left : 0, //絕對定位left
pre : -1, //上個(gè)圖片索引
curr : 0, //當(dāng)前圖片索引
next : 1, //下個(gè)圖片索引
direction : 1, //自動(dòng)播放方向
interTime : 3000//間隔時(shí)間
}
addImgAlt(imgPro.curr);
imgPro.count = $('#banner .list a img').length;
imgPro.imgConLength = imgPro.imgWidth * imgPro.count;
imgPro.left = parseInt($('#box .list ul').css("left"));
//播放定時(shí)器
var t = setInterval(imgPlay, imgPro.interTime);
$('#box .arrowl img, #box .arrowr img,#banner .list a,#box .count li,#box p').hover(function() {
clearInterval(t);
}, function() {
t = setInterval(imgPlay, imgPro.interTime);
});
// 自動(dòng)播放圖片
function imgPlay() {
if ((imgPro.next != imgPro.count && imgPro.direction == 1) || (imgPro.pre == -1 && imgPro.direction == -1)) {
imgPro.direction = 1;
toNext();
} else {
imgPro.direction = -1;
toLast();
}
}
//點(diǎn)擊左方向
$('#box .arrowl img').click(function() {
if (imgPro.curr != 0) {
toLast();
}
});
//點(diǎn)擊右方向
$('#box .arrowr img').click(function() {
if (imgPro.next != imgPro.count) {
toNext();
}
});
//點(diǎn)擊導(dǎo)航播放
$('#box .count li').click(function() {
imgPro.index = $('#box .count li').index(this);
if (imgPro.curr != imgPro.index) {
imgPro.left += (imgPro.curr - imgPro.index) * imgPro.imgWidth;
addImgAlt(imgPro.index);
play();
$('#box .count li').eq(imgPro.curr).removeClass('current').end().eq(imgPro.index).addClass('current');
imgPro.curr = imgPro.index;
imgPro.pre = imgPro.index - 1;
imgPro.next = imgPro.index + 1;
}
});
//播放
function play() {
$('#box .list ul').css({
'opacity' : '0.5'
}).animate({
'left' : imgPro.left + "px",
'opacity' : '1'
}, 'slow');
}
//添加圖片說明信息
function addImgAlt(index) {
$("#box p").text($("#banner .list a img").eq(index).attr("alt"));
}
//上一張
function toLast() {
imgPro.left += imgPro.imgWidth;
addImgAlt(imgPro.pre);
play();
$('#box .count li').eq(imgPro.curr).removeClass('current').end().eq(imgPro.pre).addClass('current');
imgPro.pre--;
imgPro.curr--;
imgPro.next--;
}
//下一張
function toNext() {
imgPro.left -= imgPro.imgWidth;
addImgAlt(imgPro.next);
play();
$('#box .count li').eq(imgPro.curr).removeClass('current').end().eq(imgPro.next).addClass('current');
imgPro.pre++;
imgPro.curr++;
imgPro.next++;
}
});
您可能感興趣的文章:
- jQuery實(shí)現(xiàn)跟隨鼠標(biāo)運(yùn)動(dòng)圖層效果的方法
- jquery 實(shí)現(xiàn)input輸入什么div圖層顯示什么
- jQuery實(shí)現(xiàn)點(diǎn)擊圖片翻頁展示效果的方法
- Jquery動(dòng)態(tài)替換div內(nèi)容及動(dòng)態(tài)展示的方法
- 基于jquery的手風(fēng)琴圖片展示效果實(shí)現(xiàn)方法
- jquery實(shí)現(xiàn)簡單易懂的圖片展示小例子
- jQuery簡單實(shí)現(xiàn)隱藏以及顯示特效
- jQuery顯示和隱藏 常用的狀態(tài)判斷方法
- jQuery焦點(diǎn)控制圖層展示延遲隱藏的方法
相關(guān)文章
jQuery判斷多個(gè)input file 都不能為空的例子
這篇文章主要介紹了jQuery判斷多個(gè)input file 都不能為空的例子,即一次性判斷多個(gè)上傳文件選擇框不能為空的方法,需要的朋友可以參考下2015-06-06HTML5+jQuery插件Quicksand實(shí)現(xiàn)超酷的星際爭霸2兵種分類展示效果(附demo源碼下載)
這篇文章主要介紹了HTML5+jQuery插件Quicksand實(shí)現(xiàn)超酷的星際爭霸2兵種分類展示效果,詳細(xì)分析了Quicksand插件的使用及圖片浮動(dòng)顯示的實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-05-05基于Jquery的文字滾動(dòng)跑馬燈插件(一個(gè)頁面多個(gè)滾動(dòng)區(qū))
文字逐行或多行滾動(dòng)跑馬燈插件,基于Jquery。命名為Jquery.RollTitle。支持在一個(gè)頁面聲明多個(gè)滾動(dòng)區(qū) (就為了要這點(diǎn)才寫了這個(gè))2010-07-07JQuery的自定義事件代碼,觸發(fā),綁定簡單實(shí)例
下面的代碼是所有它自己的自定義事件觸發(fā)。你可以綁定到這個(gè)自定義事件,并提高它時(shí),你要執(zhí)行的代碼里面綁定。2013-08-08分享精心挑選的12款優(yōu)秀jQuery Ajax分頁插件和教程
在這篇文章中,我為大家收集了12個(gè)基于 jQuery 框架的 Ajax 分頁插件,這些插件都提供了詳細(xì)的使用教程和演示2012-08-08jquery模擬多級(jí)復(fù)選框效果的簡單實(shí)例
下面小編就為大家?guī)硪黄猨query模擬多級(jí)復(fù)選框效果的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-0633個(gè)優(yōu)秀的 jQuery 圖片展示插件分享
這篇文章收集了33個(gè)優(yōu)秀的 jQuery 圖片插件分享給大家。2012-03-03