2 wggaimll wggaimll 于 2016.05.03 21:42 提问

求解释turn函数什么意思。。。
 <!DOCTYPE html>
<html lang="en"> 
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>JS幻灯代码</title> 
<script type="text/javascript">  
      window.onload = function (){   
           flag = 0;  
           obj1 = document.getElementById("slider");   
           obj2 = document.getElementsByTagName("li");       
          for (var num = 0; num < obj2.length; num++) {     
             obj2[num].onmouseover = function () 
                {  turn(this.innerHTML);   }     
              }
              }   
      function turn(value){    
           if (value != null) {     
          flag = value - 2;  } 
          /*if (flag < obj2.length - 1)     
                {flag++;  } 
          else    flag = 0; */   
        obj1.style.top = flag * (-320) + "px";  //top 属性设置一个定位元素的上外边距边界与其包含块上边界之间的偏移。
                 } 
</script> 
<style type="text/css"> 
#wrap {
    height:320px;    
    width: 320px;   
    overflow: hidden;    
    position: relative;    
    overflow: hidden;   
    } 
#wrap ul {    
    list-style: none;    
    position: absolute;    
    top: 200px;    
    left:250px;   
    }         
#wrap li  {    
    margin-left:2px;    
    opacity: .3;    
    filter: alpha(opacity=30);    
    text-align: center;    
    line-height: 20px;    
    font-size: 15px;    
    height: 20px;    
    width: 20px;    
    background-color:#666;    
    float: left;    
    border-radius:3px;    
    cursor:pointer;   
    } 
#slider  {    
    position: absolute;    
    top:0px;    
    left: 0px;   
    } 
#slider img {    
    float: left;   
    border: none;   
    } 
</style>
</head>
<body>  
    <div id="wrap" align="center" >   
     <div id="slider">    
          <a target="_blank" >
             <img src="img/20121225105638206.jpg" /></a>    
          <a target="_blank">
             <img src="img/ff40e256-86b7-4755-b6b5-38762857f201.jpg"/></a>    
          <a target="_blank" >
             <img src = "img/20130513091049491.jpg" /></a>      
      </div>  
    <ul>    
     <li>1</li>   
     <li>2</li>    
     <li>3</li>      
   </ul>
</div> 
</body>
</html>

2个回答

showbo
showbo   Ds   Rxr 2016.05.04 09:12
已采纳

obj1.style.top = flag * (-320) + "px"; 主要这句设置slider的top属性,实现里面图片的展示

bdmh
bdmh   Ds   Rxr 2016.05.03 21:47

人家已经有注释了,参数就是个数,减去2,然后参加运算

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!