jQuery幻燈

<div class="box">
	<ul class="slideImages transitionOpacity">
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
		<li class="slideImage"
			style="background:url(images/dt.jpg) center top no-repeat;"></li>
	</ul>
	<div class="options">
		<a href="javascript:;" class="prev">&lt;</a> <span class="pages">
			<a href="javascript:;">1</a> <a href="javascript:;">2</a> <a
			href="javascript:;">3</a> <a href="javascript:;">4</a> <a
			href="javascript:;">5</a> <a href="javascript:;">6</a> <a
			href="javascript:;">7</a> </span> <a href="javascript:;" class="next">&gt;</a>
	</div>
</div>
.box {
	width: 100%;
	margin: 0px auto;
	background: #000;
	overflow: hidden;
        position:relative;
}

.box .slideImages {
	position: relative;
	width: 100%;
	height: 300px;
	overflow: hidden;
}

.box .slideImages .slideImage {
	position: absolute;
	width: 100%;
	height: 300px;
}

.box .slideImages.transitionOpacity .slideImage {
	opacity: 0;
}

.box .slideImages.transitionOpacity .slideImage.current {
	opacity: 1;
}

.box .slideImages.transitionTop .slideImage {
	top: -300px;
	opacity: 0;
}

.box .slideImages.transitionTop .slideImage.current {
	opacity: 1;
	top: 0;
}

.box .slideImages .slideImage {
	transition-duration: 0.5s;
	-webkit-transition-duration: 0.5s;
	-moz-transition-duration: 0.5s;
	-o-transition-duration: 0.5s;
}

.options {
	text-align: center;
	padding: 5px 10px;
	position: absolute;
	left: 45%;
	top: 240px;
}

.options a {
	color: #fff;
}

.options a:hover {
	color: #3da636;
}

.options .prev {
	position: fixed;
	left: 20px;
	top: 130px;
	font-size: 20px;
}

.options .next {
	position: fixed;
	right: 20px;
	top: 130px;
	font-size: 20px;
}

.options .pages a {
	padding: 0 5px;
	margin: 5px;
	background: rgba(180, 20, 70, 0.8);
	border-radius: 100%;
	-webkit-box-shadow: inset 1px 1px 3px 1px #333;
}

.options .pages a.current {
	background: rgba(150, 200, 250, 0.8);
	color: #000;
}
/* 頭條滾動 */
	$(".slideImages").each(function() {
		var slideImages = $(this);
		var slideImage = $(".slideImage", slideImages);
		var pages = $(".pages");

		// 初始化
		var currentSlideNum = 0;
		slideImage.removeClass("current");
		slideImage.eq(currentSlideNum).addClass("current");
		pages.each(function() {
			var page = $("a", this);
			page.removeClass("current");
			page.eq(currentSlideNum).addClass("current");
		});

		function goToSlide(slideNum) {
			slideImage.eq(currentSlideNum).removeClass("current");
			slideImage.eq(slideNum).addClass("current");
			pages.each(function() {
				var page = $("a", this);
				page.eq(currentSlideNum).removeClass("current");
				page.eq(slideNum).addClass("current");
			});

			currentSlideNum = slideNum;
		}

		function prevSlide() {
			var prevSlideNum = currentSlideNum - 1;
			if (prevSlideNum < 0) {
				prevSlideNum = slideImage.size() - 1;
			}
			goToSlide(prevSlideNum);
		}

		function nextSlide() {
			var nextSlideNum = currentSlideNum + 1;
			if (nextSlideNum >= slideImage.size()) {
				nextSlideNum = 0;
			}
			goToSlide(nextSlideNum);
		}

		$(".prev").click(function() {
			prevSlide();
		});
		$(".next").click(function() {
			nextSlide();
		});
		$(".pages a").each(function(i) {
			if (i >= slideImage.size() || i < 0) {
				return false;
			}
			$(this).click(function() {
				goToSlide(i);
			});
		});

		// 自動

		var lastTime = 0;
		$(".prev, .next, .pages a").click(function() {
			lastTime = new Date().getTime();
		});
		setInterval(function() {
			var now = new Date().getTime();
			if (now - lastTime > 5000) {
				nextSlide();
			}
		}, 5000);
	});

來源: http://www.w3cplus.com/content/css3-transitionjavascript

相關文章
相關標籤/搜索