2016-08-13 3 views
1

Safariで無限のスクロールに問題があります。 彼は2回走って重複します。 これは私のコードです:Safariで無限のスクロールを2回追加して複製を作成する

$window.scroll(function(){ 

    if (($document.height() - $window.height()) == $window.scrollTop()) { 
     $('#loading-more svg').show(); 

     jQuery.post(
      ajaxurl, 
      { 
       'action': 'load_more', 
       'offset': offset 
      }, 
      function(response){ 
       $('#loading-more svg').hide(); 
       $('.load-more').append(response); 
       if (response) { 
        offset = offset + 4; 
       } 
      } 
     ); 
    } 
}); 

ソリューションはありますか?

ありがとうございました!

+0

他の投稿と同様に、特定のイベントをバインドして解除することができます。 – Iceman

答えて

0

を試してみてください。

$window.scroll(myEventFn); 
function myEventFn() { 
    if (($document.height() - $window.height()) == $window.scrollTop()) { 
     $window.unbind("unbind", myEventFn); //unbind specific event 
     $('#loading-more svg').show(); 

     jQuery.post(
      ajaxurl, { 
       'action': 'load_more', 
       'offset': offset 
      }, 
      function(response) { 
       $('#loading-more svg').hide(); 
       $window.scroll(myEventFn); //bind back the event 
       $('.load-more').append(response); 
       if (response) { 
        offset = offset + 4; 
       } 
      } 
     ); 
    } 
} 
0

はあなたの遅れの操作まで、特定のスクロールイベントは、あなたの場合のように重複の挙動を作成するイベントトリガの多くを蓄積防止に完了したことをバインド解除この

var scrolled = true; 
$window.scroll(function(){ 

    if (scroll == true;) { 
     scrolled = false; 
     if (($document.height() - $window.height()) == $window.scrollTop()) { 
      $('#loading-more svg').show(); 

      jQuery.post(
       ajaxurl, 
       { 
        'action': 'load_more', 
        'offset': offset 
       }, 
       function(response){ 
        $('#loading-more svg').hide(); 
        $('.load-more').append(response); 
        if (response) { 
         offset = offset + 4; 
         scrolled = true; 
        } 
       } 
      ); 
     } 
    } 
}); 
関連する問題