jquery 实现图片跳动。提示作用

需要做几件事:

第一:样式表定义

    .red   
    {
        border: 2px solid #ffffff;
    }

第二:定义抖动函数

       function shake(ele, cls, times) {
            var i = 0, t = false, o = ele.attr("class") + " ", c = "", times = times || 2;
            if (t) return;
            t = setInterval(function () {
                i++;
                c = i % 2 ? o + cls : o;
                ele.attr("class", c);
                if (i == 2 * times&&false) {
                    clearInterval(t);
                    ele.removeClass(cls);
                }
            }, 200);
        };

第三:定义抖动部件

 <span id="msg">
    @if (ViewBag.msgCount > 0)
    {
    <img id="msg_img" src="@Url.Content("~/Content/warning.png")" width="12" alt="loading"  />
    <span style="color:Red;">@ViewBag.msgCount</span>
    }
    </span>

第四:调用

   $(document).ready(function () {
            shake($("#msg"), "red", 1);
        });
           

第五:收工

posted @ 2013-08-12 18:34  shenghaishiweini  阅读(617)  评论(1编辑  收藏  举报