hsdiego
hsdiego

Reputation: 71

Highlight text on scroll

I want to make animation highlighting each letter of the text. Is there jQuery plugin to highlight text on window scoll? Trying to figure out the lightweight way to achieve this.

Upvotes: 0

Views: 4125

Answers (1)

hsdiego
hsdiego

Reputation: 71

That's what I wanted to make:

highlight();

$(window).on("scroll", function(){
  highlight();
});

function highlight(){
  var scroll = $(window).scrollTop();
  var height = $(window).height();

  $(".highlight").each(function(){
    var pos = $(this).offset().top;
    if (scroll+height >= pos) {
      $(this).addClass("active");
    } 
  });
}  

https://jsfiddle.net/4vm1sht5/3/

Upvotes: 4

Related Questions