JS随笔-HTML5图片轮播

jQuery部分
<pre name="code" class="javascript">$(".route_page1_img_slide img").swipe({//手动翻图片
		swipe : function(event, direction, distance) {
			var height = con.children(":first").outerHeight(true);
			var index = $(this).attr("rel");
			if ((direction == "right" || direction == "up") && distance > 50) {
				con.animate({
					top : -height * ((index + 1) % count)
				}, 'slow');
				$(".img_index").animate({
					top : ($(".img_index").height()) * ((index + 1) % count)
				}, 'slow')
			} else if ((direction == "left" || direction == "down") && distance > 50) {
				con.animate({
					top : -height * ((index - 1 + count) % count)
				}, 'slow');
				$(".img_index").animate({
					top : ($(".img_index").height()) * ((index - 1 + count) % count)
				}, 'slow')
			}
		}
	});

<pre name="code" class="javascript">var int = setInterval(slideview, 5000);//自动轮播
slideview = function() {
	var index;
	var current = $(".route_page1_img").offset().top;
	for (var i = 0; i < count; i++) {
		if ($("#img_" + i).offset().top == current) {
			index = i;
		}
		;
	}
	++index;
	var height = con.children(":first").outerHeight(true);
	con.animate({
		top : -height * (index % count)
	}, 'slow');
	$(".img_index").animate({
		top : ($(".img_index").height() + 4) * (index % count)
	}, 'slow')
};
css和jsp
.route_page1_img{width:100%;height: 500px; overflow:hidden; position:relative;}
.route_page1_img_slide{width:100%; height:2750px;position:absolute;}
.route_page1_img_slide img{width:100%;height: 500px;}
.route_page1_img_index{position: absolute; width: 70px;height: 210px;left: 30px;top:0px;z-index: 5}
.route_page1_img_index img{width: 50px;height: 50px;}
.img_index{position: absolute; width: 70px;height: 70px;z-index: 10}
<span style="font-family: Arial, Helvetica, sans-serif;"><pre name="code" class="plain"><div class="route_page1_img"></span>
			<div class="route_page1_img_index">
				<img class="img_index" src="dot1.png" />//当前图片所在点
				<ul>
					<c:forEach items="图片个数" var="item" >
						<li><img src="dot2.png" /></li>//一张图片对应一个点
					</c:forEach>
				</ul>
			</div>
			<div class="route_page1_img_slide">
				<c:forEach items="图片源" var="item" varStatus="status">
					<img id="img_${status.index}" rel="${status.index}" src="图片地址" />
				</c:forEach>
			</div>
		</div>

 图片 dot1.png dot2.png

还有2个封装好的js文件 jquery.touchSwipe.js    jquery.1.8.3.min.js

希望有帮助,也希望大牛看到能指点!


 
</pre><pre name="code" class="javascript">

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值