Change Background Colour on Scroll

CSS

body {
  transition: background-color 1s ease;
}
.color-blue {
  background-color: #2F8FED;
}
.color-green {
  background-color: #4DCF42;
}
.color-yellow {
  background-color: #FAEB33;
}
.color-orange {
  background-color: #F19031;
}
.color-red {
  background-color: #F2293A;
}

Javascript

<script>jQuery(function($){
    $(window).scroll(function() {

  // selectors
  var $window = $(window),
      $body = $('body'),
      $panel = $('.panel');

  // Change 33% earlier than scroll position so colour is there when you arrive.
  var scroll = $window.scrollTop() + ($window.height() / 3);

  $panel.each(function () {
    var $this = $(this);

    // if position is within range of this panel.
    // So position of (position of top of div <= scroll position) && (position of bottom of div > scroll position).
    // Remember we set the scroll to 33% earlier in scroll var.
    if ($this.position().top <= scroll && $this.position().top + $this.height() > scroll) {

      // Remove all classes on body with color-
      $body.removeClass(function (index, css) {
        return (css.match (/(^|\s)color-\S+/g) || []).join(' ');
      });

      // Add class of currently active div
      $body.addClass('color-' + $(this).data('color'));
    }
  });

}).scroll();
});</script>

Code per Section

CSS class: panel
Attributes: data-color|blue

Download Link

https://elementor-addon-components.com/add-your-custom-attributes-with-elementor/

Best Web Tools

The Ultimate Hosting Deal – Up to 75% Off + Extra 10% Today!

T&Cs Apply

Powerful, lightning-fast hosting at the lowest price. Get up to 75% off all Hostinger plans – and for a limited time, use coupon MRWEB at checkout for an extra 10% off! Don’t miss out!

Omnisend is the ultimate email & SMS marketing platform designed to boost sales with powerful automation, advanced segmentation, and seamless integrations. Convert visitors into buyers effortlessly.
T&Cs Apply
If you’re serious about growing your online business, you need an email marketing system that doesn’t just send emails—it drives sales. Omnisend is the #1 email & SMS marketing platform designed for businesses that want automation, personalization, and high conversions—without the headache.