视差滚动与移动的单词/字母 [英] Parallax scrolling with moving word/letters

查看:73
本文介绍了视差滚动与移动的单词/字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,需要基本上复制网站标题的字母与滚动一起移动的效果(就像这里: https://en.playkot.com/ ,这个单词PLAYKOT)。

I'm doing a project where it's required to basically replicate the effect where the letters of the site title move along with scrolling (exactly like here: https://en.playkot.com/, this word PLAYKOT).

你知道如何在滚动,不同方向和不同长度的字母移动时如何实现这种效果?我不确定scrollmagic和/或补间之间的相互作用。

Do you have any idea how can I achieve that effect when letters move during scrolling, in different directions and different lengths? I'm not sure about the interplays between scrollmagic and/or tweens.

推荐答案

我设法解决了这个问题,看看这里:
使用完整页面视图(最好在我的 CODEPEN 上)正确查看请注意,因为这不是(但可以很容易地变成)响应版本。

I managed to solve the problem, have a look here: Use Full page view (preferably on my CODEPEN) to properly see the effect please, as this is not (but can be easily turned into) responsive version.

jQuery(document).ready(function( $ ) {
    var $main = $("#header");
    var $header_container = $(".header-container");
    var $image = $(".h-image");
    var $parallax_word = $(".parallax-word");
    var $pw_item = $(".pw-item");
    var winH = $(window).height();

    var controller = new ScrollMagic.Controller();
    var scene1p = new ScrollMagic.Scene({
    	duration: winH
    });

    var tween1 = new TimelineMax();
    tween1.to($main, 1, {
              y: -winH / 4,
              ease: Linear.easeNone
    });

    scene1p.setTween(tween1);
    controller.addScene(scene1p);

    var scene2p = new ScrollMagic.Scene({
    	duration: winH
    });

    var tween2 = new TimelineMax();
    tween2.to($image, 1, {
    	opacity: 0.65,
        ease: Linear.easeNone
    });

    scene2p.setTween(tween2);
    controller.addScene(scene2p);

    $pw_item.each(function(index, element) {

    	var $symbol = $(this);
    	var shiftH = $symbol.data("shift");

    	var tweenI = new TimelineMax();
    	tweenI.fromTo($symbol, 1, {
    		y: shiftH * winH / 2
            }, {
            y: 0
            });

    	var scenep = new ScrollMagic.Scene({
    		duration: .7 * $main.height()
    	});

    	scenep.setTween(tweenI);
    	controller.addScene(scenep);
    });

    var scene4p = new ScrollMagic.Scene({
    	duration: winH
    });

    var tween4 = new TimelineMax();
    tween4.to($parallax_word, 1, {
        y: -winH / 5,
        ease: Linear.easeNone

    });

    scene4p.setTween(tween4);
    controller.addScene(scene4p);
	});

#header {
        background-color: #ebebed;
        position: fixed;
        left: 0;
        width: 100%;
        height: 100%;
        transform-style: preserve-3d;
        backface-visibility: hidden;
    }

    .header-container {
        background: #000;
        opacity: 1;
        height: 100%;
        transition: opacity .35s;
        transition-duration: .175s;
    }

    .header-background, .header-background .h-image {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
    }

    .header-background {
        z-index: 0;
        -webkit-transform: scale(1.1);
        -ms-transform: scale(1.1);
        transform: scale(1.1);
    }

    .header-background .h-image {
         background: linear-gradient( rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2) ), url(http://eskipaper.com/images/universe-background-1.jpg);
        background-size: cover;
        background-position: 80% 80%;
        position: relative;
        display: block;
        left: 0px;
        top: 0px;
        transform-style: preserve-3d;
        backface-visibility: hidden;
    }

    .parallax-word {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        display: -webkit-flex;
        display: -moz-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-justify-content: space-between;
        -moz-box-pack: justify;
        -ms-flex-pack: justify;
        justify-content: space-between;
        -webkit-align-items: center;
        -moz-box-align: center;
        -ms-flex-align: center;
        align-items: center;
        padding: 0 20%;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 1;
    }

    .pw-item {
        position: relative;
        width: 120px;
        height: 200px;
        z-index: 1;
    }

    .pw-item.pw-item-1 {
      width: 110px;
    }
    .pw-item.pw-item-2 {
      width: 140px;
    }
    .pw-item.pw-item-3,
    .pw-item.pw-item-4 {
        width: 140px;
    }
    .pw-item.pw-item-5.pw-item-shift {
      width: 120px;
    }
    .pw-item.pw-item-6 {
      width: 160px;
    }

    .pw-letter {
        font-family: 'Arial';
        font-size: 160px;
        font-weight: 700;
        color: #fff;
        line-height: 1;
        position: absolute;
        display: block;
        left: 0px;
        top: 0px;
        transform-style: preserve-3d;
        backface-visibility: hidden;
        opacity: 1 !important;
    }

    .symbol {
        display: block;
        opacity: 1;
    }

    #body_content {
        background-color: #000;
        height: 2000px;
    }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/animation.gsap.min.js"></script>

<div id="project">	
  <section id="header">	
    <div class="header-container">
			<div class="header-background">
				<div class="h-image"></div>
			</div>
			<div class="parallax-word">
				<div class="pw-item pw-item-1" data-shift="-0.25">
					<div class="pw-letter h-image">
						<span class="symbol">y</span>
					</div>
				</div>
				<div class="pw-item pw-item-2" data-shift="0.15">
					<div class="pw-letter h-image">
						<span class="symbol">w</span>
					</div>
				</div>
				<div class="pw-item pw-item-item_3" data-shift="-0.3">
					<div class="pw-letter h-image">
						<span class="symbol">e</span>
					</div>
				</div>
				<div class="pw-item pw-item-4 pw-item-shift" data-shift="0">
					<div class="pw-letter h-image">
						<span class="symbol">t</span>
					</div>
				</div>
				<div class="pw-item pw-item-5" data-shift="-0.35">
					<div class="pw-letter h-image">
						<span class="symbol">k</span>
					</div>
				</div>
				<div class="pw-item pw-item-6" data-shift="0.15">
					<div class="pw-letter h-image">
						<span class="symbol">a</span>
					</div>
				</div>
			</div>
		</div>
  </div>  
  <div id="body_content">
  </div>
</div>

谢谢大家利益! :-)我希望它能帮助别人。
PS:这个片段是一个更大的项目的一部分,所以可能有一些未使用的部分,对不起,但这个想法应该是非常明显的。

Thanks everyone for interest! :-) I hope it'll help someone. PS: This snippet is part of a bigger project, so there might be some unused parts, sorry for that, but the idea should be quite obvious.

这篇关于视差滚动与移动的单词/字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆