0

我想显示和图像 2 秒钟,然后隐藏它以显示图表。我的部分是图表在 2 秒后出现,但我不知道如何放置图像。

$("li").click(function(){
    //Toggle List
    $(this).toggleClass("active");
    $(this).next("div").stop('true','true').slideToggle();
    //SHOW image for 2 seconds and then HIDE IT
    var did = $(this).attr('id');
    var graphic;

    if($(this).next("div").html() == '')
        {
        graphic = '';
            $.ajax({
               url: 'pulse.php?did='+did, success: function(data)
             {
             graphic = data;
             }
        });
    }

    //Here I show the chart after 2 seconds pulling the data from pulse.php...
delay(function(){               
    $("#"+did).next("div").html(graphic);
    }, 2000 );
});


    //Delay function
var delay = (function(){
var timer = 0;
         return function(callback, ms){
         clearTimeout (timer);
         timer = setTimeout(callback, ms);
     };
})();
4

1 回答 1

0

如果您已经在工作,我想这只是在正确的位置显示和隐藏图像元素的问题:

$("li").click(function(){
    $("#imageElementID").show(); //show image on click
    $(this).toggleClass("active");
    $(this).next("div").stop('true','true').slideToggle();
    //SHOW image for 2 seconds and then HIDE IT
    var did = $(this).attr('id'), graphic;
    if ($(this).next("div").html() === '') {
        graphic = '';
        $.ajax({
            url: 'pulse.php?did='+did, 
            success: function(data) {
                graphic = data;
            }
        });
    }
    delay(function(){               
        $("#imageElementID").hide(); //hide image after some sort of delay function ?
        $("#"+did).next("div").html(graphic);
    }, 2000 );
});​
于 2012-07-03T00:30:27.993 回答