那种焦点图轮换,
本来是按照一定的顺序的,
关键是下面这点

鼠标一放到焦点上,
顺序就改变了,
这个,
是怎么做到的分析一下这一点就好了,不用,帖源码的,谢谢~

解决方案 »

  1.   

    猜测是由setInterval()周期性调用函数实现轮播,触发onmouseover()事件时调用clearInterval()方法中断轮播,然后设置起始对象,再重新使用setInterval()执行轮播代码。
      

  2.   

    做了个小试验,发现还需要额外维持一只记录上一次鼠标位置的对象的索引号。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    body { background-color:#CCC; }
    table { border-collapse:collapse; margin:100px auto; }
    tr { height:100px; }
    td { width:100px; border:1px solid #FFF; }
    td.show { background-color:#900; }
    </style><script type="text/javascript">
    window.onload = function() {
    var current = 0, int, lastMouseonIndex = -1;
    var obj = document.getElementById('demo').getElementsByTagName('td');
    for( var i = 0; i < obj.length; i ++) obj[i].onmouseover = function() {
    var mouseonIndex = this.parentNode.cells.length * this.parentNode.rowIndex + this.cellIndex;
    if (mouseonIndex != lastMouseonIndex) {
    int = window.clearInterval(int);
    current = mouseonIndex;
    int = window.setInterval(play, 1000);
    }
    }
    function play() {
    for (var i = 0; i < obj.length; i ++) obj[i].className = '';
    current %= obj.length;
    obj[current].className = 'show';
    current ++;
    }
    int = window.setInterval(play, 1000);
    }
    </script>
    </head><body>
    <table border="0" id="demo">
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
    </table>
    </body>
    </html>