Jump to content

Reveal text horizontal on scroll

Recommended Posts

Posted

Add a Code Block > Paste this code

<div class="text-wrapper">
  <div class="text-container">
    <h1 class="h1">eu sou um texto que vai para a esquerda</h1>
  </div>
</div>

<div class="text-wrapper2">
  <h2>fim</h2>
</div
  <style>
  .text-wrapper {
  height: 250vh;
  background: #eee;
  position: relative;
  z-index: 0;
}

.text-wrapper2 {
  height: 100vh;
  background: #fff;
  position: relative;
  z-index: 2;
}

.text-container {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  position: fixed;
  top: 30%;
  width: 100%;
}

h2, .h1 {
  font-size: 120px;
  word-break: keep-all;
  color: #444;
  transform: translateX(0px);
  margin-left: 30%; /* começa no meio*/
}

h2 {
  padding: 50px 0;
  margin: 0;
  text-align: center;
}

  </style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(document).ready(function ($) {
  $(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    // Pra deixar mais lento só dividir o scroll por / 2 ou 3
    // para ele ficar mais tempo na tela aumentar a altura do wrapper
    $(".h1").css("transform", "translateX(-" + scroll + "px)");
  });
});

</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 5/9/2022 at 8:55 AM, tuanphan said:

Add a Code Block > Paste this code

<div class="text-wrapper">
  <div class="text-container">
    <h1 class="h1">eu sou um texto que vai para a esquerda</h1>
  </div>
</div>

<div class="text-wrapper2">
  <h2>fim</h2>
</div
  <style>
  .text-wrapper {
  height: 250vh;
  background: #eee;
  position: relative;
  z-index: 0;
}

.text-wrapper2 {
  height: 100vh;
  background: #fff;
  position: relative;
  z-index: 2;
}

.text-container {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  position: fixed;
  top: 30%;
  width: 100%;
}

h2, .h1 {
  font-size: 120px;
  word-break: keep-all;
  color: #444;
  transform: translateX(0px);
  margin-left: 30%; /* começa no meio*/
}

h2 {
  padding: 50px 0;
  margin: 0;
  text-align: center;
}

  </style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(document).ready(function ($) {
  $(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    // Pra deixar mais lento só dividir o scroll por / 2 ou 3
    // para ele ficar mais tempo na tela aumentar a altura do wrapper
    $(".h1").css("transform", "translateX(-" + scroll + "px)");
  });
});

</script>

 

Thanks so much! It doesn't seem to work when I paste it into code block. Should I be doing anything else? Putting the script into header code injection?

Posted
On 5/13/2022 at 11:12 PM, prcreative said:

Thanks so much! It doesn't seem to work when I paste it into code block. Should I be doing anything else? Putting the script into header code injection?

Can you share link to page where you added Code Block? We can check easier

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
11 hours ago, prcreative said:

yes, no problem. It is: https://mgfoodstuff.squarespace.com/home-1

Password: crowncreative

Thanks

A typo

Edit this line

<div class="text-wrapper2">
  <h2>fim</h2>
</div

to this

<div class="text-wrapper2">
  <h2>fim</h2>
</div>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.