Jquery autosuggest fading out too fast

Discussion in 'jQuery' started by phplebanon, Sep 24, 2014.

  1. #1
    Hello I have a jquery autosuggest that is fading out too soon:
    http://www.mirochgroup.com/MirocheGroup/
    <script type="text/javascript">
    $(function(){
    $(".search").keyup(function()
    {
    var searchid = $(this).val();
    var dataString = 'search='+ searchid;
    if(searchid!='')
    {
    $.ajax({
    type: "POST",
    url: "searchx",
    data: dataString,
    cache: false,
    success: function(html)
    {
    $("‪#‎result‬").html(html).show();
    }
    });
    }return false;
    });
    jQuery("#result").live("click",function(e){
    var $clicked = $(e.target);
    var $name = $clicked.find('.name').html();
    var decoded = $("<div/>").html($name).text();
    $('‪#‎searchid‬').val(decoded);
    });
    jQuery(document).live("click", function(e) {
    var $clicked = $(e.target);
    if (! $clicked.hasClass("search")){
    jQuery("#result").delay(4700).fadeOut('1700');
    }
    });
    $('#searchid').click(function(){
    //jQuery("#result").fadeIn("1000");
    jQuery("#result").delay(4700).fadeIn('1700');
    });
    });
    </script>
    What am I doing wrong,
    Many Thanks
     
    phplebanon, Sep 24, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Just adjust the value in the fadeOut function?
     
    PoPSiCLe, Sep 24, 2014 IP
  3. phplebanon

    phplebanon Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    I have changed it to:


    if (! $clicked.hasClass("search"))
    {
    setTimeout(function()
    {
    jQuery("#result").delay('1500').fadeOut('2800');
    },7000);
    }
    });
    $('#searchid').click(function(){
    //jQuery("#result").fadeIn("1000");
    jQuery("#result").fadeIn('1000');
    });

    Still I am having trouble, it is better but still repeating the scenariois
     
    phplebanon, Sep 24, 2014 IP
  4. Alexstorm

    Alexstorm Greenhorn

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    I'm playing with setTimeout as well and noticed that timers still seem to run from previous clicks.

    If you have a div that shows for 7 seconds and you click anything else or even refresh the page, it seems that the timer still runs and the div can disappear what looks like too soon.
     
    Alexstorm, Feb 22, 2015 IP