小程序流程如何做_完美完成js焦点轮播效果(一

日期:2021-01-12 类型:科技新闻 

关键词:微信公众号平台小程序,微信打分小程序,小程序发布,小程序大全,微信小程序编程

完美实现js焦点轮播效果(一)     -blog   这篇文章主要为大家详细介绍了完美实现js焦点轮播效果的相关代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

最简单轮播形式,js中通过pic的display属性控制变换,也可通过调整Pic的margin-Left

效果如图:

实现代码:

 !DOCTYPE html 
 html 
 head lang="en" 
 meta charset="UTF-8" 
 title /title 
 style type="text/css" 
 margin: 0;
 padding: 0;
 list-style: none;
 text-decoration: none;
 .wrap{
 width: 490px;
 height: 170px;
 margin: 100px auto;
 border: 1px solid #000000;
 position: relative;
 overflow: hidden;
 #pic{
 width: 2450px;
 height: 170px;
 #pic li{
 float: left;
 #list{
 position: absolute;
 bottom: 10px;
 left:150px ;
 #list li{
 float: left;
 width: 15px;
 height: 15px;
 background: #fff;
 margin: 0 10px;
 border-radius: 50%;
 cursor: pointer;
 #list .on{
 background: #e27a00;
 .Prev{
 top: 30px;
 left: 0;
 .Next{
 top: 30px;
 right: 0;
 .Prev,.Next{
 position: absolute;
 font-size: 80px;
 font-weight: bold;
 color:#fff ;
 -webkit-transition: all 0.35s ease-in-out
 .Next:hover,
 .Prev:hover{
 background: #ccc;
 background: rgba(204, 204, 204, 0.4);
 .show{
 display: block;
 .hidden{
 display: none;
 /style 
 script type="text/javascript" 
 window.onload=function(){
 var pic=document.getElementById('pic').getElementsByTagName('li');
 var list=document.getElementById('list').getElementsByTagName('li');
 var prev=document.getElementById('Prev');
 var next=document.getElementById('Next');
 var index=0;
 var timer=null;
 auto();
 for(var i=0;i list.length;i++){
 list[i].index=i;
 list[i]. unction(){
 clearInterval(timer);
 Change(this.index);
 list[i].onmouseout=function(){
 auto();
 pic[i]. unction(){
 clearInterval(timer);
 pic[i].onmouseout=function(){
 auto();
 prev. unction(){
 clearInterval(timer);
 index--;
 if(index =0){
 index=list.length-1;
 Change(index);
 next. unction(){
 clearInterval(timer);
 index++;
 if(index =list.length){
 index=0;
 Change(index);
 prev.onmousemove=function(){
 clearInterval(timer);
 prev.onmouseout=function(){
 auto();
 next. unction(){
 clearInterval(timer);
 next.onmouseout=function(){
 auto();
 function Change(curIndex){
 for(var i=0;i list.length;i++){
 list[i].className="";
 pic[i].className="hidden";
 list[curIndex].className="on";
 pic[curIndex].className="show";
 index=curIndex;
 function auto(){
 timer=setInterval(function(){
 index++;
 if(index =list.length){
 index=0
 Change(index);
 },2000);
 /script 
 /head 
 body 
 div id="wrap" 
 ul id="pic" 
 li a href="#" img src="/54111cd9000174cd.jpg" alt=""/ /a /li 
 li a href="#" img src="/54111dac000118af.jpg" alt=""/ /a /li 
 li a href="#" img src="/54111d9c00070.jpg" alt=""/ /a /li 
 li a href="#" img src="/54111d8a0170.jpg" alt=""/ /a /li 
 li a href="#" img src="/54111d7d00018ba.jpg" alt=""/ /a /li 
 /ul 
 ul id="list" 
 li /li 
 li /li 
 li /li 
 li /li 
 li /li 
 /ul 
 a href="javascript:;" id="Prev" /a 
 a href="javascript:;" id="Next" /a 
 /div 
 /body 
 /html 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持凡科。