Home > Web Front-end > JS Tutorial > body text

Share the example code of jquery carousel chart

零下一度
Release: 2017-06-27 10:52:41
Original
1514 people have browsed it

Today we are still carousel pictures, today we are talking about jquery carousel pictures!

First of all, we need a plug-in:

Please ignore the Zepto plug-in, it does not play any role!

That’s it!

Then there’s the code!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
	<title></title>
	<!--引入插件-->
	<script src="../上月插件/jquery-3.1.1.min.js?1.1.11"></script>
	<script src="../课件/课件/zepto.js?1.1.11"></script>
	<!--CSS样式-->
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		img{
			width: 400px;
			height: 230px;
		}
		ul{	
			/*计算全部图片的宽度*/
			width:1600px;
			height: 230px;
			list-style: none;
			/*定位*/
			position: absolute;

		}
		div{
			width: 400px;
			height: 230px;
			overflow: hidden;
			/*定位*/
			position: relative;
		}
		li{	
			/*单独图片宽度*/
			width:400px;
			float: left;
		}
	</style>
</head>
<body>
<div>
	<ul>
		<!--图片-->
		<li><img src="../img/2d.jpg"/></li>
		<li><img src="../img/2d.jpg"/></li>
		<li><img src="../img/2d.jpg"/></li>
		<li><img src="../img/2d.jpg"/></li>
	</ul>
</div>
<script type="text/javascript">
		var x = 0,TimerId;
		function strTimer(){
			TimerId = setInterval(function(){
				//判断,如果是第三张图片的时候,那么就变成第一张图片,实现循环的效果
				if(x == -1200){
					x = 0;
					$("ul :first").css("left",0 + "px");
				}
				if(x % 400 == 0){
					stop(1);
				}				
				$("ul:first").css("left",x-- + "px");
			},10);
		}
			function stop(n){
				if(n == 1){
					clearInterval(TimerId);
					setTimeout(strTimer,500);
				}else{
					clearInterval(TimerId);
				}
			}
			
		strTimer();
		(zepot);
</script>
</body>
</html>
Copy after login

That’s it, have you learned it? ??

The above is the detailed content of Share the example code of jquery carousel chart. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!