我有以下代码,当鼠标悬停在某个元素上时,会显示一个div,并隐藏在mouseout上。这适用于除IE之外的每个浏览器,这是我的代码;
// JavaScript Document
var baseopacity=0
function showtext(thetext){
if (!document.getElementById)
return
textcontainerobj=document.getElementById("tabledescription")
browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
document.getElementById("tabledescription").innerHTML=thetext
highlighting=setInterval("gradualfade(textcontainerobj)",50)
}
function hidetext(){
cleartimer()
instantset(baseopacity)
}
function instantset(degree){
if (browserdetect=="mozilla")
textcontainerobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
textcontainerobj.filters.alpha.opacity=degree
else if (document.getElementById && baseopacity==0)
document.getElementById("tabledescription").innerHTML=""
}
function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}
function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=20
else if (window.highlighting)
clearInterval(highlighting)
}
//<![CDATA[
$(window).load(function(){
$(".tiptext").mouseover(function() {
$(this).children(".description").show();
}).mouseout(function() {
$(this).children(".description").hide();
});
});//]]>
以下是其中一个元素的HTML(每个元素都是一张图片);
<div id="one">
<div class="tiptext"><a href="http://mathremake.site40.net/"><img src="../images/web/1.png" height="180" width="300"/></a>
<div class="description"><font face="Arial, Helvetica, sans-serif"><u>Ascension Math Page</u></font><font size="2" face="Arial, Helvetica, sans-serif"><br>Ascension Collegiate's Mathematics department web page.</br></font></div>
</div>
</div>
相同元素的CSS;
#one {
top: 200px;
position: absolute;
width: 300px;
position: absolute;
left: 50%;
margin-left: -500px;
}
感谢所有帮助,谢谢。 :)
答案 0 :(得分:2)
IE有$(window).load()
的问题,你可以试试这个:
$(window).bind('load', function(){
...
});
或:
$(document).ready(function() {
$(".tiptext").hover(function() {
$(this).find(".description").show();
}, function() {
$(this).find(".description").hide();
});
});
答案 1 :(得分:0)