迁移自: https://www.cnblogs.com/dashublog/p/illusion.html
人类的大脑时常会被眼睛所看到的画面所欺骗,比如下面这个例子中,黄色和蓝色的“小虫”其实是同步移动的:
不相信的同学可以自己尝试一下,页面源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <!DOCTYPE html>
<style> body { margin: 0; }
#div1 { position: relative; width: 400px; height: 300px; border: 1px solid #dddddd; }
#div1 .bar { width: 4px; height: 300px; float: left; }
#div1 .bar.b { background-color: black; }
#div1 .bar.w { background-color: white; }
#div1 .block { position: absolute; width: 16px; height: 4px; left: 0; }
#div1 .block.y { background-color: yellow; top: 140px; }
#div1 .block.b { background-color: blue; top: 160px; } </style>
<div id="div1">
</div>
<script type="text/javascript"> var div1 = document.getElementById('div1'); var tmp = []; for (var i = 0; i < 100; i++) { if (i % 2) { tmp.push('<div class="bar b"></div>'); } else { tmp.push('<div class="bar w"></div>'); } } tmp.push('<div id="blkYellow" class="block y"></div>'); tmp.push('<div id="blkBlue" class="block b"></div>'); div1.innerHTML = tmp.join(''); var blkYellow = document.getElementById('blkYellow'), blkBlue = document.getElementById('blkBlue'); var walk = function (p) { blkYellow.style.left = blkBlue.style.left = p + 'px'; window.setTimeout(function () { walk((p + 2) % 400); }, 100); }; walk(0); </script>
|