簡體   English   中英

在元素滾動而不是窗口位置上淡入div

[英]Fade out div upon element scroll not window position

我的標題根據滾動位置逐漸消失,但是我想將淡出效果附加到用戶滾動到粘性導航欄上時,以產生更好的效果。

我嘗試了以下方法,但是沒有運氣!

<script>
     $(".l-subheader.at_bottom").scroll(function() {
     $(".l-titlebar-content").css("opacity", 1 - $(".l-subheader.at_bottom").scrollTop() / 220);
     });
</script>

應該很簡單但是我是JS新手!

http://scottdavy.co.uk/our-care-plans/ http://scottdavy.co.uk/our-pricing/

謝謝你的幫助。

檢查標題是否變為position:fixed; 然后應用淡入淡出效果。

<script>
     $(".l-subheader.at_bottom").scroll(function() {
        if( $(this).css('position') == 'fixed' )
        {
           $(".l-titlebar-content").css("opacity", 1 - $(".l-subheader.at_bottom").scrollTop() / 220);
        }

     });
</script>

嘗試以下演示...平滑滾動標題和子標題

https://jsfiddle.net/pratikgavas/D3DDp/38/

JS代碼:-

$(window).on("scroll", function(e) {
 if ($(window).scrollTop() >= $("#Header").height()) {
 $("#Header").fadeOut(500);
 $("#SubHeader").css('top','0px');
  }else {
    $("#Header").fadeIn(500);
 $("#SubHeader").css('top','100px');
}

});

暫無
暫無

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

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