基于jQuery的仿flash的廣告輪播代碼
更新時(shí)間:2010年11月04日 22:03:17 作者:
很多網(wǎng)站的首頁(yè)都有廣告輪播,今天閑來看了一網(wǎng)站的首頁(yè)廣告輪播方式,是通過 jQuery的blockSlide插件實(shí)現(xiàn)的,然后自己測(cè)試了一下,很好。
整個(gè)頁(yè)面如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="_Template/js/blockSlide.js" type="text/javascript"></script>
<style type="text/css">
div#imgADPlayer
{
margin: auto;
margin-bottom: 4px;
width: 960px;
height: 120px;
background: url(../images/photo_01.jpg) left top no-repeat;
padding: 0px;
border: none;
clear: both;
position: relative;
}
div#imgADPlayer .smask
{
position: absolute;
left: 0px;
top: 0px;
}
</style>
</head>
<body>
<!-- 滾動(dòng)圖片開始 -->
<div id="imgADPlayer">
<div id="AdTop">
<div id="myjQueryContent">
<div>
<a href="javascript:void(0)">
<img src="_Template/images/photo_01.jpg" alt="" /></a></div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_02.jpg" alt="" /></a></div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_03.jpg" alt="" /></a>
</div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_04.jpg" alt="" /></a></div>
</div>
<div id="flow">
</div>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#AdTop").blockSlide({
speed: "normal",
num: 4,
timer: 3000,
flowSpeed: 300
});
});
</script>
</div>
<!--滾動(dòng)圖片結(jié)束 -->
</body>
</html>
注釋:
speed:圖片輪播速度
num:圖片數(shù)量
timer:自動(dòng)輪播的時(shí)間間隔,定時(shí)器;
flowSpeed:是滑塊移動(dòng)的速速度
blockSlide插件源碼如下:
/**
* @author huajianhuakai */
(function($)
{
$.fn.blockSlide = function(settings)
{
settings = jQuery.extend({
speed: "normal",
num: 4,
timer: 1000,
flowSpeed: 300
}, settings);
return this.each(function()
{
$.fn.blockSlide.scllor($(this), settings);
});
};
$.fn.blockSlide.scllor = function($this, settings)
{
var index = 0;
var imgScllor = $("div:eq(0)>div", $this);
var timerID;
//自動(dòng)播放
var MyTime = setInterval(function()
{
ShowjQueryFlash(index);
index++;
if (index == settings.num)
index = 0;
}, settings.timer);
var ShowjQueryFlash = function(i)
{
$(imgScllor).eq(i).animate({ opacity: 1 }, settings.speed).css({ "z-index": "100" }).siblings().animate({ opacity: 0 }, settings.speed).css({ "z-index": "0" });
}
}
})(jQuery);
復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="_Template/js/blockSlide.js" type="text/javascript"></script>
<style type="text/css">
div#imgADPlayer
{
margin: auto;
margin-bottom: 4px;
width: 960px;
height: 120px;
background: url(../images/photo_01.jpg) left top no-repeat;
padding: 0px;
border: none;
clear: both;
position: relative;
}
div#imgADPlayer .smask
{
position: absolute;
left: 0px;
top: 0px;
}
</style>
</head>
<body>
<!-- 滾動(dòng)圖片開始 -->
<div id="imgADPlayer">
<div id="AdTop">
<div id="myjQueryContent">
<div>
<a href="javascript:void(0)">
<img src="_Template/images/photo_01.jpg" alt="" /></a></div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_02.jpg" alt="" /></a></div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_03.jpg" alt="" /></a>
</div>
<div class="smask">
<a href="javascript:void(0)">
<img src="_Template/images/photo_04.jpg" alt="" /></a></div>
</div>
<div id="flow">
</div>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#AdTop").blockSlide({
speed: "normal",
num: 4,
timer: 3000,
flowSpeed: 300
});
});
</script>
</div>
<!--滾動(dòng)圖片結(jié)束 -->
</body>
</html>
注釋:
speed:圖片輪播速度
num:圖片數(shù)量
timer:自動(dòng)輪播的時(shí)間間隔,定時(shí)器;
flowSpeed:是滑塊移動(dòng)的速速度
blockSlide插件源碼如下:
復(fù)制代碼 代碼如下:
/**
* @author huajianhuakai */
(function($)
{
$.fn.blockSlide = function(settings)
{
settings = jQuery.extend({
speed: "normal",
num: 4,
timer: 1000,
flowSpeed: 300
}, settings);
return this.each(function()
{
$.fn.blockSlide.scllor($(this), settings);
});
};
$.fn.blockSlide.scllor = function($this, settings)
{
var index = 0;
var imgScllor = $("div:eq(0)>div", $this);
var timerID;
//自動(dòng)播放
var MyTime = setInterval(function()
{
ShowjQueryFlash(index);
index++;
if (index == settings.num)
index = 0;
}, settings.timer);
var ShowjQueryFlash = function(i)
{
$(imgScllor).eq(i).animate({ opacity: 1 }, settings.speed).css({ "z-index": "100" }).siblings().animate({ opacity: 0 }, settings.speed).css({ "z-index": "0" });
}
}
})(jQuery);
您可能感興趣的文章:
- PHP結(jié)合JQueryJcrop實(shí)現(xiàn)圖片裁切實(shí)例詳解
- 基于jQuery的圖片剪切插件
- jquery imgareaselect 使用利用js與程序結(jié)合實(shí)現(xiàn)圖片剪切
- php+flash+jQuery多圖片上傳源碼分享
- jQuery模擬完美實(shí)現(xiàn)經(jīng)典FLASH導(dǎo)航動(dòng)畫效果【附demo源碼下載】
- jQuery實(shí)現(xiàn)Flash效果上下翻動(dòng)的中英文導(dǎo)航菜單代碼
- jquery+easeing實(shí)現(xiàn)仿flash的載入動(dòng)畫
- JQuery上傳插件Uploadify使用詳解及錯(cuò)誤處理
- Jquery插件之多圖片異步上傳
- Jquery ajaxsubmit上傳圖片實(shí)現(xiàn)代碼
- jQuery Ajax文件上傳(php)
- jQuery實(shí)現(xiàn)模擬flash頭像裁切上傳功能示例
相關(guān)文章
jQuery實(shí)現(xiàn)帶延時(shí)功能的水平多級(jí)菜單效果【附demo源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)帶延時(shí)功能的水平多級(jí)菜單效果,可實(shí)現(xiàn)響應(yīng)鼠標(biāo)事件延時(shí)展示菜單的功能,涉及jQuery結(jié)合時(shí)間函數(shù)動(dòng)態(tài)操作頁(yè)面元素屬性的相關(guān)技巧,需要的朋友可以參考下2016-09-09
jQuery+php實(shí)時(shí)獲取及響應(yīng)文本框輸入內(nèi)容的方法
這篇文章主要介紹了jQuery+php實(shí)時(shí)獲取及響應(yīng)文本框輸入內(nèi)容的方法,涉及jQuery響應(yīng)鍵盤事件及ajax調(diào)用php文件針對(duì)輸入內(nèi)容的處理與回調(diào)相關(guān)技巧,非常簡(jiǎn)單易懂,需要的朋友可以參考下2016-05-05
jQuery學(xué)習(xí)筆記之基礎(chǔ)中的基礎(chǔ)
本文是jQuery學(xué)習(xí)筆記系列文章的第一篇,跟大多數(shù)開篇文章一樣,我們來講解下jQuery最基礎(chǔ)的東西,希望大家能夠喜歡。2015-01-01
jQuery實(shí)現(xiàn)圖片與文字描述左右滑動(dòng)自動(dòng)切換的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)圖片與文字描述左右滑動(dòng)自動(dòng)切換的方法,涉及jquery實(shí)現(xiàn)圖文滑動(dòng)切換效果的方法,涉及jquery針對(duì)頁(yè)面元素與樣式的相關(guān)操作技巧,需要的朋友可以參考下2015-07-07
使用jquery動(dòng)態(tài)加載js文件的方法
這篇文章主要介紹了使用jquery動(dòng)態(tài)加載js文件的方法,需要的朋友可以參考下2014-12-12

