簡體   English   中英

jQuery淡入div時到達頁面的開始

[英]Jquery fade div in when reached beginning of page

嗨,我有一個網站,用戶可以在其中水平滾動而不是垂直滾動。 當有人滾動或單擊右側的向右箭頭時,我有一個div,它會作為淡出的背景圖像保留,但是當您向左滾動而未到達頁面開頭時,背景會淡入。

我需要幫助使div(#bgvid)在用戶到達頁面開頭時淡入。

這是我當前的代碼

    $(document).ready(function() {
var distance = $('#bgvid').offset().left;
    var left = $(window).scrollLeft();


    var $item2 = $('div.inner-group-container'), //Cache your DOM selector
    visible2 = 1, //Set the number of items that will be visible
    index2 = 0, //Starting index
    endIndex2 = ( $item2.length ); //End index
    var w = $("div.inner-group-container").width();

$('#arrowR').click(function(){
      index2++;
      $item2.animate( { scrollLeft: '+=' + w + 'px'}, 800 );
      $("#bgvid").fadeOut();
});


$('#arrowL').click(function(){
    if(index2 > 0){
      index2--;
      $item2.animate( { scrollLeft: '-=' + w + 'px'}, 800 );
    }


    if ( left >= distance ) {
       $("#bgvid").fadeIn();
    }


});



$(window).bind('mousewheel', function(event) {
    var scroller = $('body').scrollLeft();


    if (event.originalEvent.wheelDelta >= 0) {

      console.log(distance);
      console.log(scroller);

      if ( scroller == distance ) {
             $("#bgvid").fadeIn();
      }


      if(index2 > 0){
        index2--;            
        $item2.animate( { scrollLeft: '-=' + w + 'px'}, 800 );
      }

      }else {
          $item2.animate( { scrollLeft: '+=' + w + 'px'}, 800 );
          index2++;
          $("#bgvid").fadeOut();

      }
});



});

答案在這里: 使用jQuery檢測水平滾動div的結尾

if ( $(document).scrollTop() == ( $(document).height() - $(window).height() ) {
  // Do something here ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM