<style>
#div1{width:500px;height:100px;background:#888;font-size:5px;margin:0 auto;color:yellow;line-height:100px}
</style>
<script>
window.onload = function ()
{
var box = document.getElementById("div1");
//var timer; box.onclick = function ()
{
var i = 1; timer = setInterval(function () {
box.style.display = i++ % 3 ? "none" : "block";
if(i>12) clearInterval(timer);
}, 100)
}
};
</script> <body>
<div id="div1">通过setInterval定时器,用三元运算符来控制元素的显示/隐藏来闪动元素</div>
</body>
</html>
05-11 22:50