Parallax Caption移至首页

时间:2015-05-20 07:33:21

标签: javascript parallax

我的标题“TEST CAPTION”有问题,因为在移动滚动后,标题会跳到顶部。我需要将标题与近图像同步。

onStop

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PARALLAX</title>
<style type="text/css">
    body {
        margin: 0px;
        background: url(http://th09.deviantart.net/fs70/PRE/i/2013/215/a/3/bubble_background_by_diversekitty-d6giw39.png) fixed;
        min-height: 2000px;
    }

    #content_layer {
        position: absolute;
        /*min-height: 100%;*/
    }

    #paralax_div1 {
        position:fixed;
        background: url(http://www.agencjaface.com/wp-content/uploads/marek_wlodarczyk_icon.jpg) no-repeat 600px 400px;
        width:100%;
        height:800px;
    }

    #caption {
        position: fixed;
        top: 500px;
        left: 300px;
        font-size: 20px;
        width:100%;
    }

</style>

    <script>
        function parallax() {
            var paralax_div1 = document.getElementById("paralax_div1");
            var caption = document.getElementById("caption");

            paralax_div1.style.top = -(window.pageYOffset / 80)+'px';
            caption.style.top = -(window.pageYOffset / 80)+'px';


        }

        window.addEventListener("scroll", parallax, false);

    </script>

</head>
<body>

    <div id="paralax_div1"></div>
    <div id="caption"> TEST CAPTION </div>
    <div id="content_layer">
        <script>
            for( i =0; i < 100; ++i) {
                document.write('HEHEHEHEHEH <BR/>');
            }
        </script>
    </div>
</body>
</html>