国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

基于jquery實現圖片廣告輪換效果代碼

2019-11-20 23:46:10
字體:
來源:轉載
供稿:網友
效果圖:

實現代碼:
復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hotmarquee</title>
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
body
{
font: 12px;
padding-top: 50px;
padding-right: 200px;
padding-bottom: 100px;
padding-left: 200px;
}
ul
{
list-style: none;
}
img
{
padding: 2px;
border: 1px solid #eee;
}
a
{
outline: none;
}
#imgs
{
width: 410px;
margin-right: auto;
margin-left: auto;
}
.top, .btm
{
background: url(../images/sprite.gif) no-repeat;
overflow: hidden;
}
.top
{
background-position: 0 0;
height: 5px;
}
.btm
{
height: 7px;
}
.mid
{
width: 400px;
padding: 5px 7px 0;
border: 1px solid #999;
}
.mid ul
{
width: 400px;
height: 600px;
background: #fff;
position: relative;
overflow: hidden;
}
.mid ul li
{
width: 400px;
height: 600px;
position: absolute;
left: 490px;
top: 0;
}
.mid ul li.first
{
left: 0;
}
#img_list
{
width: 486px;
height: 20px;
padding-top: 5px;
overflow: hidden;
height: 1%;
}
#img_list a
{
display: block;
width: 14px;
height: 14px;
text-indent: -9999px;
float: left;
margin-right: 5px;
background: url(../images/sprite.gif) no-repeat 0 -13px;
}
#img_list a:hover, #img_list a.active
{
background-position: -14px -13px;
}
</style>
<script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
var curr = 0, next = 0, count = 0;
$(document).ready(function () {
// 記錄圖片的數量
count = $('#img_list a').size();
t = setInterval('imgPlay()', 3000);
// 鼠標移動到圖片或導航上停止播放,移開后恢復播放
$('#imgs li, #img_list a').hover(function () {
clearInterval(t);
}, function () {
t = setInterval('imgPlay()', 3000);
});
//點擊導航播放到相應的圖片
$('#img_list a').click(function () {
// index()函數返回當前導航的下標
var index = $('#img_list a').index(this);
if (curr != index) {
play(index);
curr = index;
};
return false;
});
});
// 播放圖片的函數
var imgPlay = function () {
next = curr + 1;
// 若當前圖片播放到最后一張,這設置下一張要播放的圖片為第一張圖片的下標
if (curr == count - 1) next = 0;
play(next);
curr++;
// 在當前圖片的下標加1后,若值大于最后一張圖片的下標,則設置下一輪其實播放的圖片下標為第一張圖片的下標,而next永遠比curr大1
if (curr > count - 1) { curr = 0; next = curr + 1; }
};
// 控制播放效果的函數
var play = function (next) {
// 當前的圖片滑到左邊-500px,完成后返回到右邊490px
// 下一張圖片滑到0px處,完成后導航的焦點切換到下一個點上
$('#imgs li').eq(curr).css({ 'opacity': '0.5' }).animate({ 'left': '-500px', 'opacity': '1' }, 'slow', function () {
$(this).css({ 'left': '490px' });
}).end()
.eq(next).animate({ 'left': '0px', 'opacity': '1' }, 'slow', function () {
$('#img_list a').siblings('a').removeClass('active').end().eq(next).addClass('active');
});
};
</script>
</head>
<body>
<div id="imgs">
<div class="mid">
<ul>
<li class="first"><a
target="_blank">
<img src="http://meinv.vs2010.com/DownLoad/2011-7-6/e9c17b8d52e14757b03729fe57dac21f.jpg"
alt="1" /></a></li>
<li><a target="_blank">
<img src="http://meinv.vs2010.com/DownLoad/2011-7-2/2aaaba4b512c4af9ad335d962ea1b00e.jpg"
alt="2" /></a></li>
<li><a target="_blank">
<img src="http://meinv.vs2010.com/DownLoad/2011-7-1/622f65f85622417f8c19a47545265c41.jpg"
alt="3" /></a></li>
<li><a target="_blank">
<img src="http://meinv.vs2010.com/DownLoad/2011-6-25/81575b5f42ff417e85c13f9a77054f8c.jpg"
alt="4" /></a></li>
</ul>
<div id="img_list">
<a href="#1" class="active">1</a> <a href="#2">2</a> <a href="#3">3</a> <a href="#4">
4</a>
</div>
</div>
</div>
</body>
</html>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 明光市| 汉川市| 红原县| 济源市| 江安县| 托克逊县| 时尚| 平原县| 大荔县| 盘锦市| 莆田市| 抚州市| 盈江县| 新干县| 嵊州市| 满洲里市| 山西省| 彭水| 涿州市| 林芝县| 岑巩县| 亳州市| 张掖市| 安远县| 中宁县| 双辽市| 信阳市| 平定县| 淮南市| 庄河市| 鄂托克前旗| 前郭尔| 大石桥市| 吴桥县| 股票| 电白县| 凉山| 台北市| 津市市| 永和县| 永新县|