DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 一個簡單的js鼠標劃過切換效果
一個簡單的js鼠標劃過切換效果
編輯:關於JavaScript     
上次幫朋友寫過的一個簡單切換效果,超級簡單,但也比較適用.因為用到了CSS Sprite技術,DEMO中附帶了IE6兼容png的JS.

核心JavaScript代碼:點此查看DEMO
復制代碼 代碼如下:
//@Mr.Think獲取對象屬性兼容方法
function $(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);// W3C DOM
} else if (document.all && document.all(objectId)) {
return document.all(objectId);// MSIE 4 DOM
} else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];// NN 4 DOM..this won't find nested layers
} else {
return false;
}
}
//@Mr.Think切換顯示文字和背景圖位置
function iLeftNav(type) {
var inum,i_navinfo=$("i_navinfo");
if(type=="writeblog"){
inum="-300px";
}else if(type=="sharepic"){
inum="-600px";
}else if(type=="writemsg"){
inum="-900px";
}else{
inum="-300px";
}
i_navinfo.innerHTML=$(type).innerHTML;
i_navinfo.style.backgroundPosition=inum+" 0";
}
//@Mr.Think加載鼠標莫過事件
window.onload=function(){
var liitem=$("i_blognav").getElementsByTagName("li");
for(var i=0; i<liitem.length; i++){
liitem[0].onmouseover=function(){iLeftNav("writeblog")}
liitem[1].onmouseover=function(){iLeftNav("sharepic")}
liitem[2].onmouseover=function(){iLeftNav("writemsg")}
}
}

本文是一個簡易的鼠標莫過效果,用CSS亦可以實現,但相對煩瑣. 如果需要更酷更炫一點的效果,可點此查看cssrain寫的基於jQuery的氣泡提示效果.
原文發布於Mr.Think的個人博客: http://mrthink.net/script-mousechange-simple/
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved