首页 技术 正文
技术 2022年11月15日
0 收藏 516 点赞 2,191 浏览 2065 个字

原生JS编写兼容IE6,7,8浏览器无缝自动轮播(带按钮切换)

项目要求页面兼容IE6,7,8等浏览器,我们可能会遇到这个轮播效果,轮播板块要求:无限循环、自动轮播和手动切换功能,每一次滚动一小格,网上有很多这类插件,例如:swiper等!

但是很多都是不兼容IE6,7,8这些低级浏览器的,没有办法,只能自己写一个类似的轮播插件

废话不多说,直接上代码

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.8.3-20180801.min.js"></script>
<style>
*{margin: ;padding: ;}
div{position: relative;width: 1000px;overflow: hidden;height: 100px;line-height:100px;}
ul{position: absolute;list-style: none;overflow: hidden;}
li{float: left;width: 200px;height: 100px;text-align:center;color:#fff;}
a{position: absolute;color:#fff;margin: 10px;font-size:30px;text-decoration:none;}
</style>
</head>
<body>
<div>
<ul>
<li style="background: red;"></li>
<li style="background: yellow;"></li>
<li style="background: blue;"></li>
<li style="background: black;"></li>
<li style="background: green;"></li>
<li style="background: orange;"></li>
<li style="background: skyblue;"></li>
<li style="background: blue;"></li>
<li style="background: green;"></li>
<li style="background: orange;"></li>
<li style="background: skyblue;"></li>
</ul>
<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="prev" style="left:0px;">←</a>
<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" class="next" style="right:0px;">→</a>
</div>
</body>
<script type="text/javascript">
var fli = $("ul li").clone(true);
var oul = $("ul");
oul.append(fli);
oul.width($("ul li").eq().width()*$("ul li").length);
var inow = ;
var timer = null; $("div").mouseover(function(){
clearInterval(timer);
})
$("div").mouseout(function(){
autoplay();
}) $(".next").click(function(){
if(inow == $("ul li").length/){
oul.css("left","0px");
inow = ;
}else{
inow++;
}
var leng = -inow*$("ul li").eq().width()+"px";
oul.animate({"left":leng});
})
$(".prev").click(function(){
if(inow == ){
var ml = -$("ul li").eq().width()*($("ul li").length/)+"px";
oul.css("left",ml);
inow = $("ul li").length/-;
}else{
inow--;
}
var leng = -inow*$("ul li").eq().width()+"px";
oul.animate({"left":leng});
})
function autoplay(){
timer = setInterval(function(){
if(inow == $("ul li").length/){
oul.css("left","0px");
inow = ;
}else{
inow++;
}
console.log(inow);
var leng = -inow*$("ul li").eq().width()+"px";
oul.animate({"left":leng});
},);
}
autoplay();
</script>
</html>

希望这篇文章能帮到大家,喜欢技术交流的可以关注我,一起交流前端技术。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848