jQuery滚动窗口关闭和后回窗口打开

jQuery scroll window off and after back window on

本文关键字:窗口 滚动 jQuery      更新时间:2023-09-26

我需要窗口关闭运行淡出动画从启动页面到主页。但在家里我需要的窗口上,为使一个添加类在滚动,然后我用来改变标题。这段代码不能工作:

$(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;
}

最后我试着不使用scroll off,并使用一个简单的

.show_splash{position: fixed;}

这样工作得很好!!