敢问路在何方

回顾scroll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>scroll</title>
    <script src="jquery-1-12-1.js"></script>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
    }
    .header{
        width: 100%;
        height: 50px;
        position: fixed;
        left: 0;
        top: -50px;
        background:red;
    }
    body{
        height: 3000px;
    }
</style>
<body>
    <div class="header">
         
    </div>
</body>
<script>
    $(function(){
        var flagdnow=true;
        var flagup=true;
        window.onscroll = function(){
            var scroll = $(document).scrollTop();
            if(scroll >= 400){
                if(flagdnow){
                    $(".header").animate({top:0})
                    flagdnow=false;
                    flagup=true;
                }
            }
            else{
                if(flagup){
                    $(".header").animate({top:"-50px"})
                    flagdnow=true;
                    flagup=false;
                }
            }
        }
    })
</script>
</html>

  

posted @   敢问  阅读(149)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示