2015-10-19 175 views
0

我有一個div,如果scrollTop值超過了122px就會淡入。jquery scrollTop event on mobile not working

這可以在桌面上正常工作(瀏覽器窗口縮小到低於500像素寬度以模仿手機屏幕大小),但它不適用於手機。有沒有解決辦法?

我的HTML:

<div id="topNav" class="fw"> 
    <div class="container"> 
    <div id="scrollLogo"> 
     <img src="images/dualLogoMob-scroll.png" width="63" height="30" alt=""/> 
    </div><!-- /#scrollLogo--> 
    <div class="twelve columns"> 
     <a href="#" onClick="return false;" id="mobMenuTrig" class="test">Menu</a> 
    </div><!-- /.twelve.columns--> 
    </div><!-- /.container--> 
</div><!-- /#topNav--> 

工作網址:http://www.altitude-digital.co.uk/dev/DUAL-SITE/index.php

我現在的JS:

<script> 
jQuery(document).ready(function(){ 
    jQuery("#scrollLogo").hide(); 
    jQuery(function() { 
     jQuery(window).scroll(function() { 
      if (jQuery(window).scrollTop() > 122) { 
      jQuery('#scrollLogo').fadeIn(); 
      } else { 
      jQuery('#scrollLogo').fadeOut(); 
      } 
     }); 
    }); 
}); 
</script> 
+0

'的jQuery(函數(){'這個塊也記錄準備使用其中之一。 – Jai

+0

這應該運行良好:[https://jsfiddle.net/hnyaq2hk/2/](https://jsfiddle.net/hnyaq2hk/2/) – morels

回答

0

http://jsbin.com/voxace/

overflow: scroll從刪除

要來自全國各地的地方使用寫"jQuery"饒你的手指:

<script> 
jQuery(function($){ // DOM ready and $ alias secured 

    // Free to use $ as usual 

    var $scrLogo = $('#scrollLogo'); // Cache your selectors for expensive DOM lookup 
    var $win = $(window); 

    $scrLogo.hide(); 
    $win.on("scroll load", function() { // Do on scroll but also on win load! 
    if ($(this).scrollTop() > 122) { 
     $scrLogo.stop().fadeIn(); // Use stop() to prevent anim. buildups 
    } else { 
     $scrLogo.stop().fadeOut(); 
    } 
    }); 

}); 
</script> 
+0

啊,這只是一個測試,我正在努力,但無濟於事。我已經刪除了這個div和css –

+0

@jarrettowen在手機上打開演示。它必須工作。 –

+0

感謝您查看此內容,我添加了您的代碼,但它仍然無法正常工作... –