我有以下 javascript
function fadeIn(objectID, amount) {
object = document.getElementById(objectID + 'Des');
if(amount > 0)
{
object.style.display ='block';
object.style.opacity = '0';
}
var i = 0;
animatefadein = function()
{
var MIN_OPACITY = 0;
var MAX_OPACITY = 1;
if ( (amount > 0 && object.style.opacity < MAX_OPACITY) || (amount < 0 && object.style.opacity > MIN_OPACITY))
{
var current = Number(object.style.opacity);
var newopac = current + Number(amount);
object.style.opacity = String(newopac);
setTimeout('animatefadein()', 50);
}
}
animatefadein();
if(amount < 0)
{
object.style.display ='none';
}
}
我需要将 display 设置为 none,因为如果用户浏览它们,则需要在其上放置另一个元素。
这是HTML,
<div id='products'>
<img src = './product1.png' usemap='#ourProducts' alt='Our Products' title='Hover over the names to find out more.'>
<map id='ourProducts' name='ourProducts'>
<area shape='rect' coords="55,55,210,110" href='#' id='forcePort' alt='ForcePort' title='ForcePort' onmouseover='fadeIn("forcePort",0.1)' onmouseout='fadeIn("forcePort",-0.1)'/>
<area shape='rect' coords="105,248,270,290" href='#' id='quickPort' alt='QuickPort' title='QuickPort' onmouseover='fadeIn("quickPort",0.1)' onmouseout='fadeIn("quickPort",-0.1)'/>
<area shape='rect' coords="390,260,535,303" href='#' id='scrinter' alt='Scrinter' title='Scrinter' onmouseover='fadeIn("scrinter",0.1)' onmouseout='fadeIn("scrinter",-0.1)'/>
<area shape='rect' coords="675,242,835,292" href='#' id='bugTrail' alt='Bug Trail' title='Bug Trail' onmouseover='fadeIn("bugTrail",0.1)' onmouseout='fadeIn("bugTrail",-0.1)'/>
<area shape='rect' coords="688,42,858,138" href='#' id='dataExtract' alt='CRM Data Extractor' title='CRM Data Extractor' onmouseover='fadeIn("dataExtract",0.1)' onmouseout='fadeIn("dataExtract",-0.1)'/>
</map>
<div id='productDes'>
<div id='scrinterDes'>
Data that needs to be shown!
</div>
<div id='bugTrailDes'>
</div>
<div id='quickPortDes'>
</div>
<div id='forcePortDes'>
</div>
<div id='dataExtractDes'>
</div>
</div>
</div>
如您所见,淡出不起作用。此外,如果您在 setTimeout 循环中放置一个计数器并将其打印到控制台,您会看到它在淡出事件中循环了无数次。这是有问题的网站,
只需转到显示屏上的产品,然后将鼠标悬停在产品名称上。