Jump to content

Smooth font color change on scroll

Recommended Posts

Here all script code you need

<script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>
<script>
  
gsap.set('span', { width: 0 })

gsap.timeline({
    scrollTrigger:{
      trigger: 'span',
      scrub:0.3,
      start:"top 40%",
      end:"top 20%",
      //markers:true
    }
 })
  .to('span', {
  width:'100%', 
  duration:1, ease:'none',
  stagger:1
})
</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!)

Link to comment
On 9/3/2023 at 3:51 AM, tuanphan said:
On 9/3/2023 at 3:51 AM, tuanphan said:

Here all script code you need

<script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>
<script>
  
gsap.set('span', { width: 0 })

gsap.timeline({
    scrollTrigger:{
      trigger: 'span',
      scrub:0.3,
      start:"top 40%",
      end:"top 20%",
      //markers:true
    }
 })
  .to('span', {
  width:'100%', 
  duration:1, ease:'none',
  stagger:1
})
</script>

Thank you, I tried to implement the HTML and CSS code with the javascript from you on the website, but unfortunately it still does not change the color of the text when scrolling. In addition, it breaks all the page relationships of other images and text. 

 

  • the HTML and CSS code were
Link to comment

Thank you, I tried to implement the HTML and CSS code with the javascript from you on the website, but unfortunately it still does not change the color of the text when scrolling. In addition, it breaks all the page relationships of other images and text. 
HTML: 

<h2>Scroll ...</h2>

<div class="wrap">
  <div class="wrap-container">

    <div>Silky<span>Silky</span></div>
    <div>smooth<span>smooth</span></div>
    <div>animation<span>animation</span></div>
    <div>is<span>is</span></div>
    <div>the<span>the</span></div>
    <div>hallmark<span>hallmark</span></div>
    <div>of<span>of</span></div>
    <div>any<span>any</span></div>
    <div>library.<span>library.</span></div>
    <br>
    <div>Silky<span>Silky</span></div>
    <div>smooth<span>smooth</span></div>
    <div>animation?<span>animation?</span></div>
    <br>
    <div>GSAP<span>GSAP</span></div>
    <div>has<span>has</span></div>
    <div>you<span>you</span></div>
    <div>covered.<span>covered.</span></div>

  </div>
</div>


CSS: 

body{
  margin:0;
  background-color:grey;
  height: 3a00vh;
}
h2{
  margin:20px;
  font-family: sans-serif;
  color:green;
}
.wrap{
  margin-top: 50vh;
  display: flex;
  justify-content: center;
}

.wrap-container {
  max-width: 950px;
}

div{
  position: relative;
  font-family: sans-serif;
  font-size: 36px;
  font-weight: 600;
  text-align: center;
}

div {
  display: inline-block;
}

span{
  position: absolute;
  width: 0;
  height: 100%;
  color: #0fd10f;
  left: 0;
  overflow:hidden;
  text-align: center;
}

 



 

Link to comment

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.