Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
September 26, 2022 at 5:37 pm #1366419
Hi Mike,
I would like to change the colour of the screen background as the user scrolls. I can only seem to find a plugin for elementor. Could you possibly advise how I could go about doing this?
Here is an example of what we would like to achieve: https://pocketpenguins.com/
Kind regards,
CamillaSeptember 27, 2022 at 3:36 am #1366478Hey engage24,
I achieved this by adding 5 color sections each with a custom class of: white, blue, red, yellow, and purple and each with a height of 100% with a special heading for reference:
then I added this css:.turn-white { background-color: #fafaf8; } .turn-blue { background-color: #3860be; } .turn-red { background-color: #c7102a; transition: background-color .5s ease; } .turn-yellow { background-color: #ffa100; } .turn-purple { background-color: #2b1378; }
and added this script to the end of your child theme functions.php file in Appearance ▸ Editor:
function waypoint_change_background_color_scroll() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ var $sections = $('.avia-section'); var $white = $(".white"); var $blue = $(".blue"); var $red = $(".red"); var $yellow = $(".yellow"); var $purple = $(".purple"); $white.waypoint(function(direction) { if (direction === 'down') { $sections.addClass('turn-white'); $sections.removeClass('turn-purple'); } if (direction === 'up') { $sections.removeClass('turn-white'); $sections.addClass('turn-purple'); } }, { offset: '50%' }); $blue.waypoint(function(direction) { if (direction === 'down') { $sections.addClass('turn-blue'); $sections.removeClass('turn-white'); } if (direction === 'up') { $sections.removeClass('turn-blue'); $sections.addClass('turn-white'); } }, { offset: '50%' }); $red.waypoint(function(direction) { if (direction === 'down') { $sections.addClass('turn-red'); $sections.removeClass('turn-blue'); } if (direction === 'up') { $sections.removeClass('turn-red'); $sections.addClass('turn-blue'); } }, { offset: '50%' }); $yellow.waypoint(function(direction) { if (direction === 'down') { $sections.addClass('turn-yellow'); $sections.removeClass('turn-red'); } if (direction === 'up') { $sections.removeClass('turn-yellow'); $sections.addClass('turn-red'); } }, { offset: '50%' }); $purple.waypoint(function(direction) { if (direction === 'down') { $sections.addClass('turn-purple'); $sections.removeClass('turn-yellow'); } if (direction === 'up') { $sections.removeClass('turn-purple'); $sections.addClass('turn-yellow'); } }, { offset: '50%' }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'waypoint_change_background_color_scroll');
See my demo page here.
Best regards,
MikeSeptember 28, 2022 at 9:45 am #1366670Hi Mike,
Great, thank you!
Kind regards,
CamillaSeptember 28, 2022 at 12:30 pm #1366699 -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.