zoukankan      html  css  js  c++  java
  • 【js 轮播图】

    效果图:

    html样式:

    <div id="box">
    			<img src="img/0.jpg" id="pir"/>	
    			<ul id="but">
    				<li>1</li>
    				<li>2</li>
    				<li>3</li>
    				<li>4</li>
    			</ul>
    			<div id="left"><</div>
    			<div id="right">></div>
    		</div>

    css样式:

    *{
    				margin: 0;
    				padding: 0;
    			}
    			#box{
    				 1000px;
    				height: 350px;
    				border:1px solid #ddd;
    				margin:0 auto;
    				position: relative;
    			}
    			img{
    				 100%;
    				height: 100%;
    			}
    			#but{
    				 160px;
    				height: 20px;
    				position: absolute;
    				bottom: 5%;
    				left: 45%;
    				list-style: none;
    			}
    			#but li{
    				float: left;
    				 25px;
    				height: 25px; 
    				background: antiquewhite;
    				border-radius: 50%;
    				margin-right: 10px;
    				text-align: center;
    				line-height: 25px;
    				cursor: pointer;
    			}
    			#left,#right{
    				font-size: 60px;
    				position: absolute;
    				top: 30%;
    				 0px;
    				height: 100px;
    				background:#EEE8AA;
    				line-height: 100px;
    				overflow: hidden;
    				transition: .5s;
    				cursor: pointer;
    			}
    			#left{left:10px;}
    			#right{right: 10px;}
    

     javasecipt效果:

    <script type="text/javascript">
    			var box =document.getElementById("box");
    			var Img = document.getElementById("pir");
    			var lis = document.getElementsByTagName("li");
    			var Left = document.getElementById("left");
    			var Right = document.getElementById("right");
    			var index = 0;
    			lis[0].style.backgroundColor = "darksalmon";
    //			定时器
    			var timer = setInterval(banner,2000);
    			
    			function banner(){
    				index++;
    				if(index == 4){
    					index = 0;
    				}
    				Img.src = "img/"+index+".jpg";
    				resetbg();
    				lis[index].style.backgroundColor = "darksalmon";
    			}
    			function resetbg(){
    				for(var i=0;i<lis.length;i++){
    					lis[i].style.backgroundColor = "antiquewhite";
    				}
    			}
    			for(var i=0;i<lis.length;i++){
    				lis[i].onclick = function(){
    					index = this.innerHTML - 1;
    					Img.src = "img/"+index+".jpg";
    					resetbg();
    					lis[index].style.backgroundColor = "darksalmon";
    				}
    			}
    			box.onmousemove = function(){
    				clearInterval(timer);
    				Left.style.width = Right.style.width ="50px";
    			}
    			box.onmouseout = function(){
    				timer = setInterval(banner,2000);
    				Left.style.width = Right.style.width ="0px";
    			}
    			Left.onclick = function(){
    				index--;
    				if(index == -1){
    					index = 3;
    				}
    				Img.src = "img/"+index+".jpg";
    				resetbg();
    				lis[index].style.backgroundColor = "darksalmon";
    			}
    			Right.onclick = function(){
    				index++;
    				if(index == 4){
    					index = 0;
    				}
    				Img.src = "img/"+index+".jpg";
    				resetbg();
    				lis[index].style.backgroundColor = "darksalmon";
    			}
    		</script>
    

      

  • 相关阅读:
    豆瓣api-简单跨域演示
    MVC4 验证用户登录一个特性搞定
    IIS7.5 不能加载外部引用的第三方JS,CSS,img等一系列静态文件
    三合一网站后台密码重置
    anaconda安装 (开源的Python发行版本)
    通达信指标函数说明大全
    织梦CMS如何修改中英文模板的当前位置
    微信小程序上架需要增值电信业务经营许可证ICP?
    PS抠图玻璃杯227
    PS用通道工具人物头发抠图246
  • 原文地址:https://www.cnblogs.com/FFPING/p/8357991.html
Copyright © 2011-2022 走看看