基于jquery的图片幻灯展示源码 - Web前端
作者:98wpeu发布时间:2026-07-13分类:网页前端技术浏览:2
导读:复制代码代码如下://图片幻灯展示$(function(){varimgPRo={imgwidth:626,//图片宽度imgConlength:0,...
复制代码 代码如下:
//图片幻灯展示
$(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++;
}
});
//图片幻灯展示
$(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++;
}
});
- 上一篇:基于jQuery的实现简单的分页控件 - Web前端
- 下一篇:已经是最后一篇了
相关推荐
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3【第六章】Foundation之按钮和下拉功能 - Web前端
- 4jQuery编写widget的一些技巧分享 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 9javascript原生和jquery库实现iframe自适应高度和宽度 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


