帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» jQuery图片轮播插件
jQuery图片轮播插件
浏览:926次
-
评论:1次
-
发布时间:2018-10-09
Html
Css
Js
Prev
Next
* { margin:0; padding:0; } .banner { width:580px; height:300px; position:relative; overflow:hidden; margin:50px auto; } .box { height:300px; position:relative; } .box div { width:580px; height:300px; position:absolute; top:0; left:0; opacity:0; transform:1.5s; -moz-transition:1.5s; -webkit-transition:1.5s; } .box div.active { opacity:1; } .box div img { width:100%; height:100%; display:block; } .but div { position:absolute; top:150px; cursor:pointer; padding:5px 15px; font-size:25px; background-color:rgba(102,215,255,0.5); color:white; z-index:2; } .next { right:50px; } .prev { left:50px; } .Dots { position:absolute; bottom:30px; right:50px; } .Dots a { width:10px; height:10px; float:left; display:block; background-color:rgba(102,215,255,0.7); margin-left:8px; border-radius:50%; } .Dots a.active { background-color:white; }
var index = 0; var Numn = ""; //获取图片的个数 $(".box").width($(".box div").width() * $(".box div").length); //获取图片的个数 var imgNum = $(".box").find('img').length; //获取每张图片的宽度 var imgWidth = $(".box").find('img').width(); //计算所有图片的宽度 var AllImgWidth = imgNum * imgWidth; // alert(AllImgWidth); function selectimg(index) { $(".box div").eq(index).addClass("active").siblings('div').removeClass('active'); $(".Dots a").eq(index).addClass("active").siblings('a').removeClass('active'); } //点击prev的按钮 $(".but .prev").click(function() { index -= 1; if (index < 0) { index = imgNum - 1; } selectimg(index); }); //点击next按钮 $(".but .next").click(function() { index += 1; if (index > 3) { index = 0; } selectimg(index); }); //鼠标放上去暂停轮播 $('.banner').hover(function() { clearInterval(p); }, function() { pic(); }); //自动轮播 // 1、轮播切换图片函数,不断的改变index的值 // 2、然后乘以宽度(总宽度) function pic() { p = setInterval(function() { index++; if (index >= imgNum) { index = 0; } selectimg(index); }, 4000); } //获取按钮的个数;向页面添加按钮 for (var icon = 0; icon < imgNum; icon++) { Numn += "
"; } $('.Dots').html(Numn); $('.Dots a').eq(0).addClass('active'); //点击.Dots a切换到对应的图 $(".Dots a").each(function(index) { $(this).click(function() { $(".box div").eq(index).addClass("active").siblings('div').removeClass('active'); $(".Dots a").eq(index).addClass("active").siblings("a").removeClass("active"); }) }); pic();
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>jQuery图片轮播插件-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:简单的jquery轮播
用户名名字过长用星号代替
非常好看的按键样式
讨论这个常用代码(1)
回答他人问题或分享心得会奖励牛币
Lv11 GM
如***歌
2021年02月23日
不错~
回复
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
926
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值