初学JS,网上找了一段JS,想自己改一改,加上个鼠标悬停后,延迟显示提示层,但是自己改了几次,都不成功哦,才疏学浅啊,请大家帮帮忙吧。
- HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Coda Bubble Example</title> <style type="text/css"> <!-- * {margin: 0;padding: 0;} body {padding: 10px;} h1 {margin: 14px 0;font-family: 'Trebuchet MS', Helvetica;} p {margin: 14px 0;font-family: 'Trebuchet MS', Helvetica;} .bubbleInfo {float:left;position: relative;width: 100px;} .trigger {position: absolute;} /* Bubble pop-up */ .popup { position: absolute; display: none; z-index: 50; border-collapse: collapse; } --> </style> <script type="text/javascript" src="http://www.codefans.net/ajaxjs/jquery1.3.2.js"></script> <script type="text/javascript"> <!-- $(function () { $('.bubbleInfo').each(function () { var distance = 10; var time = 250; var hideDelay = 200; var hideDelayTimer = null; var beingShown = false; var shown = false; var trigger = $('.trigger', this); var info = $('.popup', this).css('opacity', 0); $([trigger.get(0), info.get(0)]).mouseover(function () { if (hideDelayTimer) clearTimeout(hideDelayTimer); if (beingShown || shown) { // don't trigger the animation again return; } else { // reset position of info box beingShown = true; info.css({ top: 25, left: 15, display: 'block' }).animate({ top: '-=' + distance + 'px', opacity: 1 }, time, 'swing', function() { beingShown = false; shown = true; }); } return false; }).mouseout(function () { if (hideDelayTimer) clearTimeout(hideDelayTimer); hideDelayTimer = setTimeout(function () { hideDelayTimer = null; info.animate({ top: '-=' + distance + 'px', opacity: 0 }, time, 'swing', function () { shown = false; info.css('display', 'none'); }); }, hideDelay); return false; }); }); }); //--> </script> </head> <body> <ul> <li class="bubbleInfo"><a class="trigger" href="http://www.baidu.com">111</a> <span class="popup"> <a title="Read the release notes" href="./releasenotes.html">release notes</a><br><img src="http://www.baidu.com/img/baidu_sylogo1.gif"/> </span> </li> <li class="bubbleInfo"><a class="trigger" href="http://www.baidu.com">222</a> <span class="popup"> <a title="Read the release notes" href="./releasenotes.html">release notes11222</a> </span> </li> <li class="bubbleInfo"><a class="trigger" href="http://www.baidu.com">333</a> <span class="popup"> <a title="Read the release notes" href="./releasenotes.html">release note3333</a> </span> </li> </ul> </body> </html>