2

この遅延読み込みコードを使用しています。

JS コード:

$(window).on('scroll touchmove', function(){
  if( $('.touch').length) {
    var images = $('.theme-slider img[data-lazy]');
    images.each(function(index){
        if(isElementVisible(this)) {
            $(this).attr('src', $(this).attr('data-lazy'));
            $(this).removeAttr('data-lazy');
        }
    })
    if(images.length == 0) { 
        $(window).off('scroll touchmove');
    }
  }
});


// Checking if an image is within the viewport
function isElementVisible(el){ 
  var rect = el.getBoundingClientRect();
  return (
    rect.top >= 0 && 
    rect.left >= 0 &&
    rect.bottom <= (window.innerHeight) &&
    rect.right <= (window.innerWidth)   
  );    
}

私の問題は、画像がロードされないビューポートに入った場合に水平にスクロールしているときにiPhoneにあり、機能するまで前後にスクロールする必要があります。どうすれば解決できますか?

4

0 に答える 0