JS實(shí)現(xiàn)的文字與圖片定時(shí)切換效果代碼
本文實(shí)例講述了JS實(shí)現(xiàn)的文字與圖片定時(shí)切換效果代碼。分享給大家供大家參考。具體如下:
這是近來(lái)門(mén)戶們都喜歡用的特效,左側(cè)是一個(gè)大圖片,右側(cè)是對(duì)應(yīng)文字,鼠標(biāo)移動(dòng)時(shí),對(duì)應(yīng)行的文字會(huì)變化,圖片也相應(yīng)的切換,如果沒(méi)有鼠標(biāo)動(dòng)作時(shí),它會(huì)自己播放,播放時(shí)間可調(diào)整,個(gè)人感覺(jué)挺不錯(cuò)的導(dǎo)航效果。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-txt-pic-time-cha-tab-codes/
具體代碼如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文字與圖片切換</title>
<style>
*{margin:0;padding:0;border:0;list-style:none}
.focusPic{width:500px; margin:0 auto; clear:both; text-align:center; border:1px solid #ccc;}
.focusPic .focusTitle{width:240px;float:right; font-size:14px; text-align:left;}
.focusPic .focusTitle li{height:28px; line-height:28px; cursor:pointer; font-size:12px; padding-left:10px; }
.focusPic .focusTitle li a ,.focusPic .focusTitle li a:visited { color:#000;}
.focusPic .focusTitle li a:hover {color:#bc2931;}
.focusPic .focusTitle .current a ,.focusPic .focusTitle .current a:visited { color:#bc2931;}
.focusPic .focusTitle .current a:hover {color:#bc2931;}
.focusPic #focusMenu li.current{background:#efefef;font-weight:bold;color:#bc2931;}
.focusPic #focusLeft{width:250px;overflow:hidden; float:left;background:#efefef;font-size:14px;line-height:100px;font-weight:bold;height:168px;}
.focusPic #focusLeft li{display:none;}
.focusPic #focusLeft li.current{display:block;}
</style>
</head>
<body>
<div class="focusPic">
<ul id="focusLeft">
<li class="current">VB在線出題考試系統(tǒng)</li>
<li>jQuery 仿iGoogle 主頁(yè)模塊拖動(dòng)</li>
<li>jQuery UI 官方實(shí)例集</li>
<li>VB在線出題考試系統(tǒng)</li>
<li>小妖ASP投票調(diào)查系統(tǒng) v4.0</li>
<li>jQuery 帶動(dòng)畫(huà)的日期選擇插件</li>
</ul>
<div class="focusTitle">
<ul id="focusMenu">
<li class="current"><a href="#">VB在線出題考試系統(tǒng)</a></li>
<li><a href="#" target="_blank">jQuery 仿iGoogle 主頁(yè)模塊拖動(dòng)</a></li>
<li><a href="#" target="_blank">jQuery UI 官方實(shí)例集</a></li>
<li><a href="#" target="_blank">VB在線出題考試系統(tǒng)(MSSQL)</a></li>
<li><a href="#" target="_blank">小妖ASP投票調(diào)查系統(tǒng) v4.0</a></li>
<li><a href="#" target="_blank">jQuery 帶動(dòng)畫(huà)的日期選擇插件</a></li>
</ul>
</div>
<div class="clear"></div>
</div>
<script language="javascript" type="text/javascript">
//<![CDATA[
var $ = function(id) {
return document.getElementById(id);
};
Function.prototype.bind = function() {
if (arguments.length < 2 && arguments[0] == null) {
return this;
}
var __method = this, args = $A(arguments), object = args.shift();
return function() {
return __method.apply(object, args.concat($A(arguments)));
};
};
var isArray = function(testVar) {
return Array == testVar.constructor ? 1 : String != testVar.constructor && null != testVar.length && !testVar.alert && !testVar.nodeType ? 2 : 0;
};
var $A = function(variable) {
switch (isArray(variable)) {
case 1:
return variable;
case 2:
var arr = [], i = -1, len = variable.length;
while (++i < len) {
arr[i] = variable[i];
}
return arr;
default:
return [variable];
}
};
var addClass = function(elem, className) {
if ((" " + elem.className + " ").indexOf(" " + className + " ") == -1) {
if (elem.className == "") {
elem.className = className;
} else {
elem.className += (" " + className);
}
}
};
var removeClass = function(elem, className) {
var newClass = (" " + elem.className + " ").replace(" " + className + " ", " ");
elem.className = newClass.substr(1, newClass.length - 2);
};
var addEvent = function(elem, eventName, handler) {
if (elem.addEventListener) {
elem.addEventListener(eventName, handler, false);
} else if (elem.attachEvent) {
elem.attachEvent("on" + eventName, handler);
}
};
function Slide(menus, contents, css, eventName, interval) {
var curSeq = 0, length = contents.length, timerIds = [], isStopped;
if (menus && length != menus.length) {
throw new Error("the amount of menus and contents is not equal");
}
var hide = function(seq) {
removeClass(contents[seq], css);
if (menus) {
removeClass(menus[seq], css);
}
};
var show = function(seq) {
addClass(contents[seq], css);
if (menus) {
addClass(menus[seq], css);
}
curSeq = seq;
};
this.showNext = function() {
var next = curSeq + 1;
if (next >= length) {
next = 0;
}
var i = length;
while (--i >= 0) {
if (i != next) {
hide(i);
} else {
show(i);
}
}
};
this.change = function(event) {
if (this != menus[curSeq]) {
var i = length;
while (--i >= 0) {
if (menus[i] != this) {
hide(i);
} else {
show(i);
}
}
}
e = window.event || event;
e.cancelBubble = true;
};
this.play = function(speed) {
isStopped = false;
timerIds.push(setInterval(this.showNext.bind(this), speed));
};
this.pause = function() {
isStopped = true;
var i = length;
while (--i >= 0) {
clearInterval(timerIds[i]);
timerIds.splice(i, 1);
}
};
var i = length;
while (--i >= 0) {
addEvent(menus[i], eventName, this.change.bind(menus[i]));
if (interval > 0) {
addEvent(menus[i], "mouseover", this.pause);
addEvent(menus[i], "mouseout", this.play.bind(this, interval));
}
}
if (interval > 0) {
this.play(interval);
}
}
var focusImg = new Slide($("focusMenu").getElementsByTagName("li"), $("focusLeft").getElementsByTagName("li"), "current", "mouseover", 3000);
//]]>
</script>
</body>
希望本文所述對(duì)大家的JavaScript程序設(shè)計(jì)有所幫助。
- JavaScript實(shí)現(xiàn)定時(shí)隱藏與顯示圖片的方法
- js換圖片效果可進(jìn)行定時(shí)操作
- javascript定時(shí)變換圖片實(shí)例代碼
- 最簡(jiǎn)單的js圖片切換效果實(shí)現(xiàn)代碼
- 用html+css+js實(shí)現(xiàn)的一個(gè)簡(jiǎn)單的圖片切換特效
- 純js無(wú)flash仿搜狐女人頻道FLASH圖片切換效果代碼
- js實(shí)現(xiàn)支持手機(jī)滑動(dòng)切換的輪播圖片效果實(shí)例
- js實(shí)現(xiàn)網(wǎng)頁(yè)隨機(jī)切換背景圖片的方法
- JavaScript 圖片切換展示效果alibaba拓展版
- 非常漂亮的JS+CSS圖片幻燈切換特效
- js動(dòng)態(tài)切換圖片的方法
- jQuery圖片切換插件jquery.cycle.js使用示例
- JS圖片定時(shí)翻滾效果實(shí)現(xiàn)方法
相關(guān)文章
微信小程序頁(yè)面跳轉(zhuǎn)功能之從列表的item項(xiàng)跳轉(zhuǎn)到下一個(gè)頁(yè)面的方法
這篇文章主要介紹了微信小程序頁(yè)面跳轉(zhuǎn)功能之從列表的item項(xiàng)跳轉(zhuǎn)到下一個(gè)頁(yè)面的方法,結(jié)合具體實(shí)例形式總結(jié)分析了微信小程序頁(yè)面跳轉(zhuǎn)及列表item項(xiàng)跳轉(zhuǎn)頁(yè)面的相關(guān)操作技巧,需要的朋友可以參考下2017-11-11
javascript為按鈕注冊(cè)回車(chē)事件(設(shè)置默認(rèn)按鈕)的方法
這篇文章主要介紹了javascript為按鈕注冊(cè)回車(chē)事件(設(shè)置默認(rèn)按鈕)的方法,可實(shí)現(xiàn)按下回車(chē)鍵觸發(fā)按鈕按下的效果,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-05-05
JavaScript實(shí)現(xiàn)的可變動(dòng)態(tài)數(shù)字鍵盤(pán)控件方式實(shí)例代碼
本篇文章主要介紹了JavaScript實(shí)現(xiàn)的可變動(dòng)態(tài)數(shù)字鍵盤(pán)控件方式實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了了解一下2017-07-07
純js+css實(shí)現(xiàn)仿移動(dòng)端淘寶網(wǎng)站的彈出詳情框功能
這篇文章主要介紹了純js+css實(shí)現(xiàn)仿移動(dòng)端淘寶網(wǎng)站的彈出詳情框功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
2020淘寶618理想生活列車(chē)自動(dòng)領(lǐng)喵幣js腳本的代碼
這篇文章主要介紹了2020淘寶618理想生活列車(chē)自動(dòng)領(lǐng)喵幣腳本,需要先安裝 auto.js腳本,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06

