zoukankan      html  css  js  c++  java
  • 图片轮播无缝接

    第一种方法:图片一直向左滑动,无缝接

    <!doctype html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title>Document</title>  
        <style>  
            *{  
                padding: 0;  
                margin: 0;  
            }  
            ul li{list-style-type: none}  
            #banner{  
                400px;  
                height:400px;  
                overflow: hidden;  
            }  
            #banner ul{  
                1600px;  
                overflow: hidden;  
            }  
            #banner ul>li{  
                400px;  
                height:400px;  
                float: left;  
            }  
            img{  
                max- 100%;  
            }  
        </style>  
    </head>  
    <body>  
        <div id="banner">  
            <ul>  
                <li><img src="img/adamcatlace1.jpg" alt="" width="400px" height="400px"/></li>  
                <li><img src="img/adamcatlace2.jpg" alt="" width="400px" height="400px"/></li>  
                <li><img src="img/adamcatlace3.jpg" alt="" width="400px" height="400px"/></li>  
                <li><img src="img/adamcatlace4.jpg" alt="" width="400px" height="400px"/></li>  
            </ul>  
        </div>  
        <input type="button" value="left" class="left"/>  
        <input type="button" value="right" class="right"/>  
      
      
        <script src="js/jquery-1.8.3.min.js"></script>  
        <script>  
            $(function () {  
                $('.right').click(function () {  
                    $("#banner ul").animate({marginLeft:"-400px"},600, function () {  
                        $("#banner ul>li").eq(0).appendTo($("#banner ul"));
                        $("#banner ul").css('marginLeft','0px');
                    });
                    console.log($("#banner ul").html());
                })  
                $('.left').click(function () {  
                    $("#banner ul").css('marginLeft','-400px');  
                    $("#banner ul>li").eq(3).prependTo($("#banner ul"));  
                    $("#banner ul").animate({marginLeft:"0px"},600);  
                })  
            })  
        </script>  
    </body>  
    </html> 
    

      

    第二种方法:图片向左滑动,当到最后一个一个图片,向右滑动

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<style>                   
            #a1{ 
               	400px; 
               	height:400px;
               	left:0; 
               	position:relative;  
               	overflow:hidden;   
            }
            #ta{ 
            	position:relative; 
            	left:0px; 
            	top:0px; 
            	transition:1s;
            } 
     
    </style>
    		</style>
    	</head>
    	<body>
    		<div id="a1">
    			<table id="ta" cellpadding="0" cellspacing="0" >    
    				<tr>
    					<td><img  src="img/adamcatlace1.jpg" /></td>
    					<td><img  src="img/adamcatlace2.jpg"/></td>                                  
    					<td><img  src="img/adamcatlace3.jpg"/></td>
    					<td><img  src="img/adamcatlace4.jpg"/></td>
    					<td><img  src="img/adamcatlace5.jpg"/></td>
    				</tr>
    			</table>
    		</div>
    		<script>
            //javascrpt固定格式,双标签元素
            var leftBoolse=true;
            document.getElementById("ta").style.left="0px" //将0px这个值赋值给根据id找到的left的值
    		function ff(){  
    		    // 定义一个值ta,将找到的值强制转换为整数
    	        var ta=parseInt( document.getElementById("ta").style.left);   
    	        //判断,当ta>-3200时执行的操作
    	        if(leftBoolse){
    	        	if(ta != -1600){
    	              //将ta的值减去400,(将left向左移动,原来的数是0,-400,即移动一张图的距离)
    	              document.getElementById("ta").style.left=(ta-400)+"px"; 
    	        	}else{
    	        		leftBoolse=false;
    	        	}
    	        }else{
    	        	//不满足ta>-3200时,即ta=3200时,走完五张图的时候,跳回0px,即回到第一张图
    	        	if(ta != 0){
    	        		document.getElementById("ta").style.left=(ta+400)+"px"; 
    	        	}else{
    	        		leftBoolse=true;
    	        	}
    	             
    	        }
    	        window.setTimeout("ff()",2000);
    		}
    		//延迟执行ff(),2s的时间,两秒钟换第一次图
            window.setTimeout("ff()",2000);                                       
    		</script>
    	</body>
    </html>
    

      

  • 相关阅读:
    新一代MQ apache pulsar的架构与核心概念
    Flutter使用fluwx实现微信分享
    BZOJ3622 已经没有什么好害怕的了 动态规划 容斥原理 组合数学
    NOIP2016提高组Day1T2 天天爱跑步 树链剖分 LCA 倍增 差分
    Codeforces 555C Case of Chocolate 其他
    NOIP2017提高组Day2T3 列队 洛谷P3960 线段树
    NOIP2017提高组Day2T2 宝藏 洛谷P3959 状压dp
    NOIP2017提高组Day1T3 逛公园 洛谷P3953 Tarjan 强连通缩点 SPFA 动态规划 最短路 拓扑序
    Codeforces 873F Forbidden Indices 字符串 SAM/(SA+单调栈)
    Codeforces 873E Awards For Contestants ST表
  • 原文地址:https://www.cnblogs.com/binmengxue/p/6113878.html
Copyright © 2011-2022 走看看