js单张图片平移切换效果实例分享
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了js单张图片平移切换效果实例分享,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3401字,纯文字阅读大概需要5分钟。
内容图文
![js单张图片平移切换效果实例分享](/upload/InfoBanner/zyjiaocheng/296/f27ee47bc37f4f9bb7f7acde182af260.jpg)
本文参考了JQuery实现图片切换(自动切换+手动切换)
由于个人不需要手动切换功能,因此把那部分的内容删了,主要是增加了无缝切换的效果。
原理也很简单,大概是一张图移动到左边以后,从底部移回最右,等待下一次循环。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.1.min.js"></script> </head> <body> <p class="wrapper"> <h1>jquer实现图片切换</h1> <p id="focus"> <ul> <!-- 这里有三个z-index的设置 --> <li><p class="switch_pic" style="z-index: 3;background: url('imgs/01.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="z-index: 2;background: url('imgs/02.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="z-index: 1;background: url('imgs/03.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/04.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/meiko2.jpg') center center;background-size: cover;"></p></li> <li><p class="switch_pic" style="background: url('imgs/meiko7.jpg') center center;background-size: cover;"></p></li> </ul> </p> </p> <script type="text/javascript"> $(function() { var sWidth = $("#focus").width(); var len = $("#focus ul li").length; var index = 0; var picTimer; var $pics = $("#focus ul li").find('.switch_pic');//获取所有图片 showPics(index); //网页打开立即执行一次动画 picTimer = setInterval(function() { index++; if(index == len) {index = 0;} showPics(index); },3000);//3000毫秒的间隔 //显示图片函数,根据接收的index值显示相应的内容 function showPics(index) { //普通切换 var nowLeft = -sWidth; //每次移动固定量 var $pic = $pics.eq(index);//获取当前要移出的图片 var $nexPic = $pics.eq((index+1)%len);//当前要移入的图片 var $nexnexPic = $pics.eq((index+2)%len);//下一个要移入的图片 $nexPic.css("left",sWidth);//下一个图片移动到最右 //当前要移出的图片开始左移,模式设为平滑"linear",速度和间隔一样 $pic.animate({"left":nowLeft},3000,"linear",function(){ // 当前图片完全移出后,重新设置z-index $pic.css("z-index",1); $nexPic.css("z-index",3); $nexnexPic.css("z-index",2); }); //当前要移入的图片同时左移 $nexPic.animate({"left":0},3000,"linear"); } }); </script> <style type="text/css"> *{margin:0;padding:0;} body{font-size:12px;color:#222;font-family:Verdana,Arial,Helvetica,sans-serif;background:#f0f0f0;} .clearfix:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;} .clearfix{zoom:1;} ul,li{list-style:none;} img{border:0;} .wrapper{width:800px;margin:0 auto;padding-bottom:50px;} h1{height:50px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;margin-bottom:20px;} #focus{width:450px;height:350px;overflow:hidden;position:relative;} #focus ul{height:380px;position:absolute;} #focus ul li{float:left;width:450px;height:350px;overflow:hidden;position:absolute;background:#000;} #focus ul li p{position:absolute;overflow:hidden;width: 450px;height: 350px;} </style> </body>
相关推荐:
JavaScript实现鼠标滚轮控制页面图片切换功能示例
实例详解jQuery自动或手动图片切换效果
JavaScript实现鼠标滚轮控制页面图片切换的示例代码
利用JavaScript制作图片切换的方法介绍
简单实现JavaScript图片切换效果
以上就是js单张图片平移切换效果实例分享的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的js单张图片平移切换效果实例分享全部内容,希望文章能够帮你解决js单张图片平移切换效果实例分享所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。