jquery funktion einmal aufrufen

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • jquery funktion einmal aufrufen

    Hi,
    ich habe eine Liste, an deren einzelnen li's ich ein click binde.
    Wenn ich jetzt schnell auf 2 li's klicke wird die Funktion für das 2 Element aufgerufen während die Funktion des ersten Klicks noch läuft.
    Wie kann ich das unterbinden?
    Code:
    PHP-Code:
      var obj = $(this); // das ul
      
    var triggerLis obj.find("li");
      
    triggerLis.each(function( intIndex ){
         $( 
    this ).bind "click",  function(){ swap($(this)); } );
                 
      }); 
    "I don't want to belong to any club that would accept me as a member."

    Groucho Marx

  • #2
    Bspw. ein Flag setzen, dass eine Funktion noch aktiv ist, und das erst abfragen, bevor die Funktion etwas macht.

    Ggf. hat jQuery da aber auch schon einen eingebauten Mechanismus für.
    I don't believe in rebirth. Actually, I never did in my whole lives.

    Kommentar


    • #3
      hatte ich mit auch schon gedacht aber das:
      PHP-Code:
      var inProgress true;
      // some code
      function swap(li)    {
           if(!
      inProgress){
               
      inProgress true;
            
      // some code
               
      inProgressfalse;
          }

      verhindert nicht das mehrfache aufrufen der Funktion.
      Denke mal auch das jQuery einen MEchanismus dafür hat - finde ihn aber leider nicht.....
      "I don't want to belong to any club that would accept me as a member."

      Groucho Marx

      Kommentar


      • #4
        Zitat von mcmurphy Beitrag anzeigen
        verhindert nicht das mehrfache aufrufen der Funktion.
        Natürlich nicht.

        Ich schrieb ja auch,
        Zitat von wahsaga Beitrag anzeigen
        und das erst abfragen, bevor die Funktion etwas macht.
        I don't believe in rebirth. Actually, I never did in my whole lives.

        Kommentar


        • #5
          und das erst abfragen, bevor die Funktion etwas macht.
          na wird doch als erstes in der funktion, bevor sie was macht, abgefragt?!?
          Wenn das hier im binden der li's an das click event erfolgen soll wüsste ich absolut nicht wo & wie ich das machen soll....
          PHP-Code:
           var obj = $(this); // das ul
            
          var triggerLis obj.find("li");
            
          triggerLis.each(function( intIndex ){
               $( 
          this ).bind "click",  function(){ swap($(this)); } );
                       
            }); 
          das hier hätte auch nicht den erwünschten effekt:
          PHP-Code:
          triggerLis.each(function(){
                   
          // Bind the onclick event to simply alert the
                  // iteration index value.
                      
          $( this ).bind (
                          
          "click",
                          function(){
                              if(!
          inProgress){
                                  
          inProgress true;
                                  
          swap($( this ));
                                  
          inProgressfalse;
                              }
                          }
                      );
                       
                  }); 
          Zuletzt geändert von mcmurphy; 10.11.2010, 18:44.
          "I don't want to belong to any club that would accept me as a member."

          Groucho Marx

          Kommentar


          • #6
            InProgress muss static oder global sein.

            Kommentar


            • #7
              Müsste es doch eigentlich auch sein, oder?:
              PHP-Code:
              (function($){
                  $.fn.
              swapManagement = function(options){
                      var 
              defaults = {
                          
              speed200
                      
              };
                      var 
              options = $.extend(defaultsoptions);
                      var 
              obj = $(this);
                      var 
              inProgress false;
              // etc
              })(jQuery); 
              "I don't want to belong to any club that would accept me as a member."

              Groucho Marx

              Kommentar


              • #8
                Aber habs jetzt hinbekommen:
                PHP-Code:
                        function swap(li){
                            if(!
                inProgress){
                                
                inProgress true;
                                var 
                target = $("#"+li.attr"title"));
                                
                bubble.css("left",li.position().left);
                                
                target.animate({"z-index":20"opacity":1}, options.speed,
                                    function(){
                inProgress false;}
                                );
                                
                currentItem.css({"z-index":10"opacity":0});
                                
                currentItem.removeClass("current");
                                
                currentItem =  target.addClass("current");
                                
                            }
                        } 
                THX @ Wahsaga & onemorenerd
                "I don't want to belong to any club that would accept me as a member."

                Groucho Marx

                Kommentar

                Lädt...
                X