2016-10-11 27 views
0

我需要關閉窗口運行淡出動畫從初始頁面到主頁。 但在家裏,我需要窗口,爲滾動添加一個類,然後用於更改標題。 此代碼不能工作:jQuery滾動窗口關閉和後窗後

$(window).ready(function(){ 
    $(this).one('scroll', function() { 
     $(window).off("scroll"); 
     $(".splash").slideUp("800", function() { 
      $("html, body").animate({"scrollTop":"0px"},100); 
      $(".site").delay(100).animate({"opacity":"1.0"},800); 
      $("html, body").on("scroll") 
     }); 
    }); 
}); 

能幫我找到了解決辦法?謝謝!

如果需要,這是我使用的插件類的代碼:

$(document).ready(function($) { 
    $(window).scroll(function() { 
     var sT = $(this).scrollTop(); 
     if (sT >= 200) { 
      $('header').addClass('scroll-header') 
     } else { 
      $('header').removeClass('scroll-header') 
     } 
    }); 
}); 

HTML:

<body <?php body_class(); ?>> 
<div class="show_splash"> 
    <div class="splash fade-in"> 
     <?php 
      $post_id = 93; 
      $queried_post = get_post($post_id); 
      echo $queried_post->post_content; 
     ?> 

    </div> 
</div> 
<div id="page" class="site"> 
    <header id="masthead" class="site-header cf" role="banner"> 

CSS:

.cf:before, 
.cf:after { 
    content: " "; 
    /* 1 */ 
    display: table; 
    /* 2 */ } 

.cf:after { 
    clear: both; } 

.cf { 
    *zoom: 1; } 

.bk_splash{ 
    top: 0; 
    right: 0; 
    bottom: 0; 
    left: 0; 
    margin: auto; 
} 
+0

請包括您的HTML和CSS。 –

+0

@ Ron.Basco我有添加HTML和CSS,如果需要更多的讓我知道。如果能幫助我,我將非常感激! –

+0

'$(「html,body」)。on(「scroll」)'缺少一個處理滾動事件的函數。 – Cobote

回答

0

最後我都儘量不使用滾動,並用簡單的

.show_splash{position: fixed;} 

用這種方式很好的工作!