2016-11-07 4 views
0

このフィクションでは、イメージがすべてウィンドウ内にあるときにイメージが表示されます。私はそれが75%または窓の真ん中にあるときに画像が上がって来る必要があります。私はどうすればいいですか?ウィンドウを変更する - 場所を確認する - 下から中へ

$(window).on("load",function() { 
     function fade(pageLoad) { 
     var min = 0; 
     var max = 1; 
     var threshold = 0.01; 

     $(".fade").each(function() { 
      /* Check the location of each desired element */ 
      var objectBottom = $(this).offset().top + $(this).outerHeight(); 
      var windowBottom = $(window).scrollTop() + $(window).innerHeight(); 

      /* If the element is completely within bounds of the window, fade it in */ 
      if (objectBottom < windowBottom) { //object comes into view (scrolling down) 
      if ($(this).css("opacity")<=min+threshold || pageLoad) {$(this).fadeTo(300,max);} 
      } else { //object goes out of view (scrolling up) 
      if ($(this).css("opacity")>=max-threshold || pageLoad) {$(this).fadeTo(300,min);} 
      } 
     }); 
     } fade(true); //fade elements on page-load 
     $(window).scroll(function(){fade(false);}); //fade elements on scroll 
    }); 

答えて

0

こんにちは、この解決策を見つけた:

$(window).on("load",function() { 
     $(window).scroll(function() { 
     var winheight = $(window).innerHeight(); 
     $(".fade").each(function() { 
      /* Check the location of each desired element */ 
      var objectBottom = $(this).offset().top + $(this).outerHeight(); 
      var windowBottom = $(window).scrollTop() + $(window).innerHeight(); 

      /* If the element is completely within bounds of the window, fade it in */ 
      if (windowBottom > (objectBottom - (winheight*0.65))) { //object comes into view (scrolling down) 
      if ($(this).css("opacity")==0) {$(this).fadeTo(500,1);} 
      } else { //object goes out of view (scrolling up) 
      if ($(this).css("opacity")==1) {$(this).fadeTo(500,0);} 
      } 
     }); 
     }); $(window).scroll(); //invoke scroll-handler on page-load 
    }); 
関連する問題