论坛首页 Web前端技术论坛

结合使用setTimeout和setInterval模拟QQ头像闪动

浏览 2651 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-19   最后修改:2010-01-19
注: $为jQuery方法,$(el).attr(name, [value])设置或返回元素的属性
function flashIcon(el, duration){
           if(isNaN(duration))duration = 800;
            $(el).attr("stopflash", "false");
            var handler = window.setInterval(function(){
                    if($(el).attr("stopflash")=="true"){
                            window.clearInterval(handler);
                            return;
                    }
                    el.style.marginLeft = "2px";
                    el.style.marginTop = "2px";
                    window.setTimeout(function(){
                            el.style.marginLeft = "";
                            el.style.marginTop = "";
                    },duration/2);
            }, duration)
    }

function stopFlash(el){
 $(el).attr("stopflash", "true");
}

//使用
$("img.icon").each(function(){
    flashIcon(this);
   $(this).one("click",function(){ stopFlash(this);}); //点击后停止闪动
})
   发表时间:2010-11-09  
如果你这个有很多信息来了,很多头象都在闪动,那么你一点击任意一个头象会不会都停止闪了
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics