jQuery 焦点新闻图片轮播的实现代码
本文导语: 本节内容: jQuery 焦点新闻图片轮播 完整代码: 代码示例: 图片轮播,新闻轮播,焦点新闻轮播-脚本学堂 $(document).ready(function () { var index = 0; var slideFlag = true; var length = $(".roll-news-image img").length; function showIm...
本节内容:
jQuery 焦点新闻图片轮播
完整代码:
图片轮播,新闻轮播,焦点新闻轮播-脚本学堂
$(document).ready(function () {
var index = 0;
var slideFlag = true;
var length = $(".roll-news-image img").length;
function showImg(i) {
$(".roll-news-image img")
.eq(i).stop(true, true).fadeIn(800)
.siblings("img").hide();
$(".roll-news-index li").removeClass("roll-news-index-hover");
$(".roll-news-index li").eq(i).addClass("roll-news-index-hover");
$(".roll-news-title a")
.eq(i).stop(true, true).fadeIn(800)
.siblings("a").hide();
}
showImg(index);
$(".roll-news-index li").click(function () {
index = $(".roll-news-index li").index(this);
showImg(index);
slideFlag = false;
});
function autoSlide() {
setInterval(function () {
if (slideFlag) {
showImg((index + 1) % length);
index = (index + 1) % length;
}
slideFlag = true;
}, 3000);
}
autoSlide();
});
* {
padding:0px;
margin:0px;
}
.roll-news-xxx-com {
width:480px;
height:300px;
border:solid 1px #c1c1c1;
}
.roll-news-index-hover {
background-color:white;
}
.roll-news-image img {
width:480px;
height:300px;
}
.roll-news-index {
position:relative;
top:-50px;
margin-right:5px;
float:right;
}
.roll-news-index {
}
.roll-news-index li {
list-style:none;
float:left;
font-size:12px;
font-weight:600;
width:18px;
height:16px;
line-height:16px;
cursor:pointer;
margin:0 3px;
background-image:url(/blog_article/opacity_50.png);
text-align:center;
}
.roll-news-title {
position:relative;
top:-25px;
padding-left:10px;
height:22px;
line-height:20px;
background:url(/blog_article/opacity_50.png);
}
.roll-news-title a {
font-size:12px;
text-decoration:none;
color:white;
background-color:gray
}
.roll-news-title a:hover {
color:red;
}