码迷,mamicode.com
首页 > Web开发 > 详细

简单的 js手写轮播图

时间:2019-12-01 19:10:03      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:highlight   name   win   script   over   mouse   var   settime   use   

html:

<div class="na1">
   <div class="pp">
    <div class="na">
     <img class="dd" src="../img/shouji/1.jpg">
    </div>
    <div class="na">
     <img class="dd" src="../img/shouji/1.jpg">
    </div>
    <div class="na">
     <img class="dd" src="../img/shouji/1.jpg">
    </div>
    <div class="na">
     <img class="dd" src="../img/shouji/1.jpg">
    </div>
   </div>
  </div>

css

.na1 {
 width: 1349px;
 height: 620px;
 overflow: hidden;
}
.dd {
 /* width: 100%; */
 height: 100%;
 margin-left: -586px;
}
.pp {
 width: 5396px;
 height: 620px;
 margin-left: 0px;
}
.aa {
 /* width: 100%; */
 height: 100%;
 margin-left: -586px;
}
 
js
/* 轮播图 */
 var aa=0;
 var waili=document.getElementsByClassName("pp")[0];
 var timer;
 // dingshiqi
 timer=setInterval(function(){
  waili.style.transition="1s";
  aa=aa-1349;
  if (aa<=-4077) {
   waili.style.transition="0s";
   aa=0;
  }
   waili.style.marginLeft=aa+"px";
  },2500)
 })
 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../public/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
	.na1 {
		width: 1349px;
		height: 620px;
		overflow: hidden;
	}
	
	.dd {
		/* width: 100%; */
		height: 100%;
		margin-left: -586px;
	}
	
	.pp {
		width: 5396px;
		height: 620px;
		margin-left: 0px;
	}
	
	.aa {
		/* width: 100%; */
		height: 100%;
		margin-left: -586px;
	}
	
	</style>
	<body>
		<!-- header-->
		<div class="na1">
			<div class="pp">
				<div class="na">
					<img class="dd" src="../img/shouji/1.jpg">
				</div>
				<div class="na">
					<img class="dd" src="../img/shouji/1.jpg">
				</div>
				<div class="na">
					<img class="dd" src="../img/shouji/1.jpg">
				</div>
				<div class="na">
					<img class="dd" src="../img/shouji/1.jpg">
				</div>
			</div>
		</div>
		<!-- 摸快2 -->
	</body>
</html>
<script type="text/javascript">

	// 2.轮播图
	
	$(function(){
	/* huidingbu */
	 $(window).scroll(function() {
		var hui = $(document).scrollTop();
		// alert(hui);
		// console.log(hui);
		if (hui > 300 ) {
			$(".jiantou").fadeIn();
		} else{
			$(".jiantou").fadeOut();
		}
		})
		$(".jiantou").click(function(){
			$("html,body").animate({
			scrollTop:‘0px‘},500);
	})
		
	
	// 	$(".cent211").mouseover(function(){
	
	// 		$(this).css("border-right","1px solid grey");
	// 		setTimeout(function(){
	// 			$(".cent211").css("border-right","none");
	// 		},1000);
			
	// 	});
	// $(".cent311").mouseover(function(){
	// 	$(this).css("border-right","1px solid grey");
	// 	setTimeout(function(){
	// 		$(".cent311").css("border-right","none");
	// 	},1000);
	// });
	/* 轮播图jq */
	/* var aa=0;
	var waili=$(".pp").eq(0);
	var timer;
	// dingshiqi
	timer=setInterval(function(){
		waili.css("transition","1s");
		aa=aa-1349;
		if (aa<=-4077) {
			waili.css("transition","0");
			aa=0;
		}
			waili.css("marginLeft",aa+"px");
	},2500) */
	/* 轮播图 */
	var aa=0;
	var waili=document.getElementsByClassName("pp")[0];
	var timer;
	// dingshiqi
	timer=setInterval(function(){
		waili.style.transition="1s";
		aa=aa-1349;
		if (aa<=-4077) {
			waili.style.transition="0s";
			aa=0;
		}
			waili.style.marginLeft=aa+"px";
	 },2500)
	})
	
/* 	$(".cent211").mouseover(function(){
		$(this).animate("border-right","1px solid grey").delay(1000).("border-right","none");
	}) */
</script>

  

 

简单的 js手写轮播图

标签:highlight   name   win   script   over   mouse   var   settime   use   

原文地址:https://www.cnblogs.com/zqy6666/p/11966793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!