js实例教程-基于jquery的图片幻灯展示源码

发布时间:2018-11-24 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-基于jquery的图片幻灯展示源码脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

代码如下:

//图片幻灯展示
$(function() {
VAR imgPRo = {
imgWidth : 626, //图片
imgConLength : 0, //图片总长度
index : 0, //导航锁定索引
count : 0, //图片数量
left : 0, //绝对定位left
pre : -1, //上个图片索引
curr : 0, //当前图片索引
next : 1, //下个图片索引
direction : 1, //自动播放方向
interTime : 3000//间隔时间
}
addImgAlt(imgPro.curr);
imgPro.count = $('#banner .list a img').length;
imgPro.imgConLength = imgPro.imgWidth * imgPro.count;
imgPro.left = parseint($('#box .list ul').css("left"));
//播放定时器
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);
});
// 自动播放图片
function imgPlay() {
if ((imgPro.next != imgPro.count @R_126_315@ imgPro.direction == 1) || (imgPro.pre == -1 && imgPro.direction == -1)) {
imgPro.direction = 1;
toNext();
} else {
imgPro.direction = -1;
toLast();
}

}

//点击左方向
$('#box .arrowl img').click(function() {
if (imgPro.curr != 0) {
toLast();
}
});
//点击右方向
$('#box .arrowr img').click(function() {
if (imgPro.next != imgPro.count) {
toNext();
}
});
//点击导航播放
$('#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++;
}

});

代码如下:

//图片幻灯展示
$(function() {
var imgPro = {
imgWidth : 626, //图片宽度
imgConLength : 0, //图片总长度
index : 0, //导航锁定索引
count : 0, //图片数量
left : 0, //绝对定位left
pre : -1, //上个图片索引
curr : 0, //当前图片索引
next : 1, //下个图片索引
direction : 1, //自动播放方向
interTime : 3000//间隔时间
}
addImgAlt(imgPro.curr);
imgPro.count = $('#banner .list a img').length;
imgPro.imgConLength = imgPro.imgWidth * imgPro.count;
imgPro.left = parseInt($('#box .list ul').css("left"));
//播放定时器
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);
});
// 自动播放图片
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();
}

}

//点击左方向
$('#box .arrowl img').click(function() {
if (imgPro.curr != 0) {
toLast();
}
});
//点击右方向
$('#box .arrowr img').click(function() {
if (imgPro.next != imgPro.count) {
toNext();
}
});
//点击导航播放
$('#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++;
}

});

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-基于jquery的图片幻灯展示源码全部内容,希望文章能够帮你解决js实例教程-基于jquery的图片幻灯展示源码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。