DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JS實現自動切換文字的導航效果代碼
JS實現自動切換文字的導航效果代碼
編輯:關於JavaScript     

本文實例講述了JS實現自動切換文字的導航效果代碼。分享給大家供大家參考。具體如下:

這裡介紹支持自動切換文字的導航菜單效果,實際上看上去並不像菜單,猛一看倒像是一個Select下拉框,兩側帶有箭頭控制按鈕,點擊左側則向上切換菜單文字,點擊右側則切換到一個菜單項內容,也可自動切換,鼠標不點擊的時候菜單會自動變化文字。

運行效果截圖如下:

在線演示地址如下:

http://demo.jb51.net/js/2015/js-auto-cha-font-nav-style-codes/

具體代碼如下:

<HTML>
<HEAD>
<TITLE>變化的文字導航條</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
</HEAD>
<BODY bgColor=#fef4d9>
<CENTER>變化的文字導航條</CENTER><BR>
<CENTER>
<TABLE borderColor=#99FFFF border=5 borderlight="green">
 <TBODY>
 <TR>
  <TD>
   <STYLE>.scrollerstyle {
BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BACKGROUND: #ffffff; BORDER-LEFT: #000000 1px solid; CURSOR: hand; BORDER-BOTTOM: #000000 1px solid; FONT-FAMILY: webdings
}
</STYLE>
<SCRIPT language=javascript>
 var msgs = new Array(
   "歡迎光臨小站",
   "網易娛樂",
   "搜狐門戶",
   "央視國際" ); 
 var msg_url = new Array(
   "http://www.sina.com",
   "http://www.163.com",
   "http://www.sohu.com",
   "http://www.cctv.com" ); 
 var target_url = new Array(
   "0",
   "0",
   "0",
   "1" );
var barwidth=350 //Enter main bar width in px or %
var setdelay=2000 //Enter delay between msgs, in mili-seconds
var mouseover_color='#B5D0FF' //Specify highlight color
var mouseout_color='#FFFFFF' //Specify default color
var count=0;
var ns6=document.getElementById&&!document.all
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
if (ie4||ns6){
document.write('<form name="news_bar"><input type="button" value="3" onclick="moveit(0)" class="scrollerstyle" style="width:22; height:22; border-right-width:0px;" name="prev" title="Previous News"><input type="button" name="news_bar_but" onclick="goURL();" style="color:#000000;background:' + mouseout_color + '; width:'+barwidth+'; height:22; border-width:1; border-color:#000000; cursor:hand" onmouseover="this.style.background=mouseover_color" onmouseout="this.style.background=mouseout_color"><input type="button" value="4" onclick="moveit(1)" class="scrollerstyle" style="width:22; height:22; border-left-width:0px;" name="next" title="Next News"></form>');
}
else{
document.write('<form name="news_bar"><input type="button" value="Previous" onclick="moveit(0)">')
if (navigator.userAgent.indexOf("Opera")!=-1)
document.write('<input type="button" name="news_bar_but" onclick="goURL();" style="width:'+barwidth+'" border="0">')
else
document.write('<input type="button" name="news_bar_but" onclick="goURL();" width="'+barwidth+'" border="0">')
document.write('<input type="button" value="Next" onclick="moveit(1)"></form>')
}
function init_news_bar(){
 document.news_bar.news_bar_but.value=msgs[count];
}
function moveit(how){
if (how==1){ //cycle foward
if (count<msgs.length-1)
count++
else
count=0
}
else{ //cycle backward
if (count==0)
count=msgs.length-1
else
count--
}
document.news_bar.news_bar_but.value=msgs[count];
}
function tick_bar(){
setInterval("moveit(1)",setdelay)
}
function goURL(){
 if(target_url[count]=="0")
 {
 location.href=msg_url[count];
 }
 else
 {
 window.open(msg_url[count]);
 }
}
tick_bar(); // delete this line if you don't want messages to tick
init_news_bar();
</SCRIPT>
 </TD></TR></TBODY></TABLE></CENTER>
</BODY>
</HTML>

希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved