欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您的位置:DIVCSS5首页 > HTML >

HTML基础必学列表

原生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>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h16912.shtml

我要分享到:
上一篇:流动图片切换效果制作
下一篇:没有了

必备CSS教程 Essential CSS Tutorials

必备HTML基础教程 Essential HTML Tutorials

 

如对文章有任何疑问请提交到DIV CSS论坛,或有任何网页制作CSS问题立即到CSS论坛发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。
CSS教程文章修订日期:2017-01-07 20:17 原创:DIVCSS5
本文www.divcss5.com DIVCSS5版权所有。