帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 一个简单的轮播图效果
一个简单的轮播图效果
浏览:684次
-
评论:0次
-
发布时间:2018-11-15
Html
Css
Js
* { margin:0; padding:0; } ol li,ul li { list-style:none; float:left; } ol { position:relative; background:#aaaaaa; overflow:hidden; height:350px; } ol>li { width:100%; height:100%; } ol>li>ul { width:100%; height:100%; } /*切换上一张下一张图片的图标样式*/ ol>li:first-child { position:absolute; left:0; right:0; top:50%; z-index:3; height:30px; line-height:30px; margin-top:-15px; } ol>li:first-child>ul>li { width:30px; text-align:center; opacity:0.3; background:#fafafa; border-radius:50%; font-weight:bold; display:none; } ol>li:first-child>ul>li:first-child { margin-left:20px; } ol>li:first-child>ul>li:first-child::after { content:'<'; font-size:14px; } ol>li:first-child>ul>li:last-child { float:right; margin-right:20px; } ol>li:first-child>ul>li:last-child::before { content:'>'; font-size:14px; } /*图片上的圆点的样式*/ ol>li:last-child { position:absolute; left:0; right:0; bottom:20px; height:10px; z-index:3; } ol>li:last-child>ul { width:125px; margin:0 auto!important; float:none; } ol>li:last-child>ul>li { width:5px; height:5px; margin:10px; background:#fafafa; opacity:0.5; border-radius:50%; } .hover { background:green!important; }
$(function() { var t, i = 1; //轮播的方法 function play2() { t = window.setInterval(function() { i >= 5 ? i = 1 : i++; //设置背景图片 $("#ol>li").eq(1).css({ 'background': 'url("http://www.sucainiu.com/themes/images/demo/500x300-' + i + '.png")', 'background-size': '100% 100%', 'background-repeat': 'no-repeat' }); //判断圆点的样式 $("#ol>li").last().children().children().eq((i - 1)).addClass('hover').siblings().removeClass('hover'); }, 1000); } //放在轮播图上显示上一张、下一张图标并停止轮播 $('#ol').hover(function(e) { $('#ol li').first().children().children().show(); //停止轮播 window.clearInterval(t); e.preventDefault(); }, function(e) { $('#ol li').first().children().children().hide(); window.clearInterval(t); play2(); e.preventDefault(); }); //上一张 $("#ol>li:first-child>ul>li:first-child").click(function() { i <= 1 ? i = 5 : i--; //设置背景图片 $("#ol>li").eq(1).css({ 'background': 'url("http://www.sucainiu.com/themes/images/demo/500x300-' + i + '.png")', 'background-size': '100% 100%', 'background-repeat': 'no-repeat' }); //判断圆点的样式 $("#ol>li").last().children().children().eq((i - 1)).addClass('hover').siblings().removeClass('hover'); }); //下一张 $("#ol>li:first-child>ul>li:last-child").click(function() { i >= 5 ? i = 1 : i++; //设置背景图片 $("#ol>li").eq(1).css({ 'background': 'url("http://www.sucainiu.com/themes/images/demo/500x300-' + i + '.png")', 'background-size': '100% 100%', 'background-repeat': 'no-repeat' }); //判断圆点的样式 $("#ol>li").last().children().children().eq((i - 1)).addClass('hover').siblings().removeClass('hover'); }); //根据圆点显示图片 $("#ol>li:last-child>ul>li").hover(function() { //设置背景图片 $("#ol>li").eq(1).css({ 'background': 'url("http://www.sucainiu.com/themes/images/demo/500x300-' + ($(this).index() + 1) + '.png")', 'background-size': '100% 100%', 'background-repeat': 'no-repeat' }); //判断圆点的样式 $("#ol>li").last().children().children().eq($(this).index()).addClass('hover').siblings().removeClass('hover'); }, function() {}); });
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
2.1.4
<!doctype html><html><head><meta charset="utf-8"><title>一个简单的轮播图效果-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:这是一个替换背景图片实现的轮播图
这个轮播是替换了<ol>标签下的第二个<li>标签背景图片实现的轮播,我使用的jquery的版本是3.2.1。在这个页面中我使用了一个拼图ui的响应式框架设置了ol的宽度,在小屏幕上响应的样式就有点难看了。
JS井字棋游戏
带吸边效果的drag自由拖拽
讨论这个常用代码(0)
回答他人问题或分享心得会奖励牛币
〒_〒 居然一个评论都没有……
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
684
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值