开发者

delay in jquery function

I want to delay this function

jquery:

    function simple_tooltip(target_items, name){
        $(target_items).each(function(i){
            $("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
            var my_tooltip = $("#"+name+i);

            $(this).removeAttr("title").mouseover(function(){
                开发者_开发问答    my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(1000);
            }).mousemove(function(kmouse){
                    my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
            }).mouseout(function(){
                    my_tooltip.fadeOut(10);
            });
        });
    }

    simple_tooltip("a.news_toltip","tooltip");

html:

<a class="news_toltip" href="http://test.com" title="Title">Link</a>


Take a look at setTimeout()

var delay = 1000; // one second
setTimeout(function(){
    simple_tooltip("a.news_toltip","tooltip");
}, delay);


You can use this for whatever function you want:

setTimeout('simple_tooltip("a.news_toltip","tooltip")', delayTimeYouWant)

while delayTimeYouWant is in millisecond: (1000 means 1 second)


Have you looked at Javascript's setTimeout?

Depending on what you want to delay (this isn't entirely clear from your question), you could either put it around a specific fadeIn/Out call or around the call to the tooltip function itself.

setTimeout( function_name, timeout_in_ms );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜