帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 最简单的jQuery轮播图
最简单的jQuery轮播图
浏览:555次
-
评论:0次
-
发布时间:2017-03-27
Html
Css
Js
<
>
#lunbobox { width:500px; height:300px; position:relative; } .lunbo { width:500px; height:300px; } .lunbo img { width:500px; height:300px; position:absolute; top:0px; left:0px; } #lunbobox ul { width:285px; position:absolute; bottom:10px; right:0px; z-index:5; } #lunbobox ul li { cursor:pointer; width:10px; height:4px; border:1px solid #cccccc; float:left; list-style:none; background:#cccccc; text-align:center; margin:0px 5px 0px 0px; } #toleft { display:none; width:30px; height:100px; font-size:40px; line-height:100px; text-align:center; color:#f4f4f4; /*background:#cccccc; */ /*background:url("../images/toleft.jpg")no-repeat center; */ position:absolute; top:90px; left:12px; cursor:pointer; z-index:99; opacity:0.4; } #toright { display:none; width:30px; height:100px; font-size:40px; line-height:100px; text-align:center; color:#f4f4f4; /*background:#cccccc; */ position:absolute; top:90px; right:0px; cursor:pointer; z-index:99; opacity:0.4; }
///轮播 $(function() { //$("#toright").hide(); //$("#toleft").hide(); $('#toright').hover(function() { $("#toleft").hide() }, function() { $("#toleft").show() }) $('#toleft').hover(function() { $("#toright").hide() }, function() { $("#toright").show() }) }) var t; var index = 0; /////自动播放 t = setInterval(play, 3000) function play() { index++; if (index > 4) { index = 0 } // console.log(index) $("#lunbobox ul li").eq(index).css({ "background": "#999", "border": "1px solid #ffffff" }).siblings().css({ "background": "#cccccc", "border": "" }) $(".lunbo a ").eq(index).fadeIn(1000).siblings().fadeOut(1000); }; ///点击鼠标 图片切换 $("#lunbobox ul li").click(function() { //添加 移除样式 //$(this).addClass("lito").siblings().removeClass("lito"); //给当前鼠标移动到的li增加样式 且其余兄弟元素移除样式 可以在样式中 用hover 来对li 实现 $(this).css({ "background": "#999", "border": "1px solid #ffffff" }).siblings().css({ "background": "#cccccc" }) var index = $(this).index(); //获取索引 图片索引与按钮的索引是一一对应的 // console.log(index); $(".lunbo a ").eq(index).fadeIn(1000).siblings().fadeOut(1000); // siblings 找到 兄弟节点(不包括自己) }); /////////////上一张、下一张切换 $("#toleft").click(function() { index--; if (index <= 0) //判断index<0的情况为:开始点击#toright index=0时 再点击 #toleft 为负数了 会出错 { index = 4 } console.log(index); $("#lunbobox ul li").eq(index).css({ "background": "#999", "border": "1px solid #ffffff" }).siblings().css({ "background": "#cccccc" }) $(".lunbo a ").eq(index).fadeIn(1000).siblings().fadeOut(1000); // siblings 找到 兄弟节点(不包括自己)必须要写 }); // $("#imgbox a ")获取到的是一个数组集合 。所以可以用index来控制切换 $("#toright").click(function() { index++; if (index > 4) { index = 0 } console.log(index); $(this).css({ "opacity": "0.5" }) $("#lunbobox ul li").eq(index).css({ "background": "#999", "border": "1px solid #ffffff" }).siblings().css({ "background": "#cccccc" }) $(".lunbo a ").eq(index).fadeIn(1000).siblings().fadeOut(1000); // siblings 找到 兄弟节点(不包括自己) }); $("#toleft,#toright").hover(function() { $(this).css({ "color": "black" }) }, function() { $(this).css({ "opacity": "0.3", "color": "" }) }) /// ///////鼠标移进 移出 $("#lunbobox ul li,.lunbo a img,#toright,#toleft ").hover( ////////鼠标移进 function() { $('#toright,#toleft').show() clearInterval(t); }, ///////鼠标移开 function() { //$('#toright,#toleft').hide() //alert('aaa') t = setInterval(play, 3000) function play() { index++; if (index > 4) { index = 0 } $("#lunbobox ul li").eq(index).css({ "background": "#999", "border": "1px solid #ffffff" }).siblings().css({ "background": "#cccccc" }) $(".lunbo a ").eq(index).fadeIn(1000).siblings().fadeOut(1000); } })
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.9.1
<!doctype html><html><head><meta charset="utf-8"><title>最简单的jQuery轮播图-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:自写jQuery轮播图
CSS动画控制左右轮播
常用jQuery Nav切换
讨论这个常用代码(0)
回答他人问题或分享心得会奖励牛币
〒_〒 居然一个评论都没有……
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
555
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值