这么用原生js自动轮播展示产品图片

发布时间:2022-03-14 17:18:46 作者:iii
来源:亿速云 阅读:153

今天小编给大家分享一下这么用原生js自动轮播展示产品图片的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>原生js自动轮播展示产品图片</title>

<meta name="keywords" content="原生js,自动轮播,展示,产品图片" />

<meta name="description" content="原生js自动轮播展示产品图片" />

<link rel="stylesheet" type="text/css" href="css/style.css">

</head>

 

<body>

<div class="user_callback"> 

         <div class="user_pic" id="user_pic">  

                   <span class="prev"></span>   <span class="next"></span>  

                   <ul id="user_call">   

                            <li class="user_pic1">

                                     <a href="#"> <img src="images/57f8c4ccN6a433b82.png" alt="1" width="248" height="285" /></a>

                            </li>   

                            <li class="user_pic2">

                                     <a href="#"> <img src="images/57f8c4d6Nd425f6a3.png" alt="2" width="247" height="285" /></a>

                            </li>   

                            <li class="user_pic3">

                                     <a href="#"> <img src="images/57f8c4e1Nbd6f109e.png" alt="3" width="248" height="285" /></a>

                            </li>   

                            <li class="user_pic4">

                                     <a href="#"> <img src="images/57f8c4ecN92c22efc.png" alt="4" width="247" height="285" /></a>

                            </li>   

                            <li class="user_pic5">

                                     <a href="#"> <img src="images/583691e7Na26009a0.png" alt="5" width="247" height="285" /></a>

                            </li>   

                            <li class="user_pic6">

                                     <a href="#"> <img src="images/583691e7Ne2adc3c4.png" alt="6" width="247" height="285" /></a>

                            </li>   

                            <li class="user_pic7">

                                     <a href="#"> <img src="images/583691e7N058f6f5a.png" alt="7" width="247" height="285" /></a>

                            </li>   

                            <li class="user_pic8">

                                     <a href="#"> <img src="images/583691e7N36b67a44.png" alt="8" width="247" height="285" /></a>

                            </li>   

                   </ul> 

         </div>

</div>

<script type="text/javascript">function arcSlip()

  {

          var oPic=document.getElementById('user_pic');

          var oPrev=getByClass(oPic,'prev')[0];

          var oNext=getByClass(oPic,'next')[0];

          

          var aLi=oPic.getElementsByTagName('li');

          

          var arr=[];

          

          for(var i=0;i<aLi.length;i++)

          {

            var oImg=aLi[i].getElementsByTagName('img')[0];

           

                  arr.push([parseInt(getStyle(aLi[i],'left')),parseInt(getStyle(aLi[i],'top')),

                              getStyle(aLi[i],'zIndex'),oImg.width,parseFloat(getStyle(aLi[i],'opacity')*100)]);

          }

          

          

          oPrev.onclick=function moveTP()

          {

              arr.push(arr[0]);

                    arr.shift();

                        for(var i=0;i<aLi.length;i++)

                  {

                                 var oImg=aLi[i].getElementsByTagName('img')[0];

                                              

                                               aLi[i].style.zIndex=arr[i][2];

                                               startMove(aLi[i],{left:arr[i][0],top:arr[i][1],opacity:arr[i][4]});

                                               startMove(oImg,{width:arr[i][3]});

                             }

                           

          }

          

         oNext.onclick=function moveTN()

          {

               arr.unshift(arr[arr.length-1]);

                     arr.pop();

                        for(var i=0;i<aLi.length;i++)

                  {

                                 var oImg=aLi[i].getElementsByTagName('img')[0];

                                              

                                               aLi[i].style.zIndex=arr[i][2];

                                               startMove(aLi[i],{left:arr[i][0],top:arr[i][1],opacity:arr[i][4]});

                                               startMove(oImg,{width:arr[i][3]});

                             }

          }

    var moveTime = setInterval (function(){

        

                   oNext.click();

                  

                   },1000);

         $('#user_pic').hover(function(){

                   ;;

         clearInterval(moveTime);

            },function(){

        moveTime=setInterval(function(){ 

                   oNext.click();            

                   },1000);

            });

                                    

 function getStyle(obj,name)

          {

                if(obj.currentStyle){ return obj.currentStyle[name]; }

                      else{ return getComputedStyle(obj,false)[name]; }

          }

  }

function getByClass(oParent,sClass)

  {

      var aResult=[];

           var aEle=oParent.getElementsByTagName('*');

          

                     for(var i=0;i<aEle.length;i++)

                     {

                             if(aEle[i].className==sClass)

                             {

                                     aResult.push(aEle[i]);

                             }

                     }

           return aResult;

  }

function getStyle(obj,name)

  {

       if(obj.currentStyle)

            {

                return obj.currentStyle[name];

            }

      

            else

            {

                return getComputedStyle(obj,false)[name];

            }

  }

 function startMove(obj,json,fnEnd)

  {

       clearInterval(obj.timer);

       obj.timer=setInterval(function()

            {

                    var bStop=true;

                    for(var attr in json)

              {     

                               var cur=0;

        

                               if(attr=='opacity')

                               {

                                               cur=Math.round(parseFloat(getStyle(obj,attr))*100);

                               }

                               else

                               {

                                               cur=parseInt(getStyle(obj,attr));

                               }

                    

                               var  speed=(json[attr]-cur)/6;

                               speed=speed>0?Math.ceil(speed):Math.floor(speed);

                     

                               if(cur!=json[attr]) bStop=false;

                             

                               if(attr=='opacity')

                               {

                                        obj.style.filter='alpha(opacity:'+(cur+speed)+')';

                                        obj.style.opacity=(cur+speed)/100;

                               }

                               else

                               {

                                        obj.style[attr]=cur+speed+'px';

                               }

                    }

                    

                    if(bStop)

                    {

                        clearInterval(obj.timer);

                             if(fnEnd) fnEnd();

                    }

                    

            },30)

  }

  arcSlip();

</script>

</body>

</html>

以上就是“这么用原生js自动轮播展示产品图片”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. bootstrap轮播如何停止自动轮播
  2. 原生js无缝轮播插件怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js

上一篇:JS的闭包与定时器这么实现

下一篇:angularJS的ng-bind-html指令这么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》