Featured Plugin - HYPERCHILD

Beautiful Design, create Child Themes in a single click!

Latest Posts

Divi Hype - Visual Builder Dropdown Navigation Menu - Blog Cover

How to create an Awesome Divi Builder dropdown Navigation Menu

Speed up your website development workflow with our amazing Divi Builder dropdown navigation menu!

DiviHype - How to install Facebook Messenger Chat on your Divi Website

How to add Facebook Messenger Chat to your Divi Website

Introduction It's well known that having a direct method for your website visitors to...
Divi Hype - mobile-parallax

How to add mobile Parallax to your Divi website

IntroductionIf you've landed here, you are probably using Divi to design websites and...
Divi Hype - How to Redirect Divi Filtered Portfolio Items to Custome URLs

How to Redirect Divi Filterable Portfolio items to custom URLs

** UPDATE 25/07/2019 ** I had several requests to update this code so it worked with later...
Divi Hype - How to Create a Divi Child Theme

How to Create a Divi Child Theme

Creating a child theme for Divi or Wordpress is essential if you want to make your own...
Divi Hype - How to create a cool Typewriter Effect in Divi

How to Create a Cool Typewriter Effect in Divi

A recent question was posted up on the Divi Web Designers Facebook group asking how to...
Divi Hype - How to Reveal Divi Content on clicking a Button

How to Reveal Divi Content on Clicking a Button

I recently saw a request on the Divi Web Designers Facebook group asking how to reveal...
Divi Hype - How to create a slide-in mobile menu for Divi

How to create a slide-in Mobile Menu for Divi

Most Divi designers will tell you the one thing that usually gives away a Divi site is the menu....
Divi Hype-How to add an email link to the Divi Person Module

How to add an email link to the Divi Person Module

People often ask how you can add an email link to the Divi Person module. It seems an obvious...

Introduction

If you’ve landed here, you are probably using Divi to design websites and want your parallax backgrounds to work on mobile devices.
For some reason Parallax on mobile seems seems to be some kind of taboo in the website development world. I’ve no idea why, I personally think it looks pretty cool. I also don’t know why Elegant Themes deliberately exclude mobile parallax in Divi. It would be great to have as an option you can switch on/off instead.

The good news is that if you want Divi Parallax to work on mobile devices, I’ve figured it out for you with a bit of simple jQuery.

Why use this?

  • It’s lightweight so doesn’t add significant code to your websites.
  • It’s simple to set up.
  • It works for parallax background images on Divi SECTIONS, ROWS, COLUMNS or MODULES.
  • It works if you have MULTIPLE sections on the same page all with parallax effects.
  • It uses the same parallax formula as Divi
  • It’s MORE EFFICIENT than standard Divi Parallax code *

* Divi continuously applies parallax settings to all parallax elements on your page, whether they are visible (In the viewport) or not. This code checks and only applies the parallax effect if the element/section is visible, reducing the amount of CSS updates happening on the page.

The code

Here’s the code you need to add to the head of your pages. In your WordPress Admin area, go to Divi > Theme Settings > Integration, then paste this into the Add code to the < head > of your blog box:

<script>
jQuery(document).ready(function($) {

  // Mobile device check
  $is_mobile_device = null !== navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/);

  if ($is_mobile_device) {

    // Function to check if an element is in the Viewport
    isInViewport = function(elem) {
        elementTop = elem.offset().top, elementBottom = elementTop + elem.outerHeight(), viewportTop = $(window).scrollTop(), viewportBottom = viewportTop + $(window).height();
        return elementBottom > viewportTop && elementTop < viewportBottom;
    };

    // Apply Parallax transform calculations when scrolling
    $(window).scroll(function() {
        $(".et_parallax_bg").each(function() {
           var $this_parent = $(this).parent();
           // Check if the parent element is on-screen
           var $is_visible = isInViewport($this_parent);
           if ($is_visible) {
             element_top = $this_parent.offset().top,
             parallaxHeight = $(this).parent(".et_pb_fullscreen").length && $(window).height() > $this_parent.innerHeight() ? $(window).height() : $this_parent.innerHeight(),
             bg_height = .3 * $(window).height() + parallaxHeight,
             main_position = "translate(0, " + .3 * ($(window).scrollTop() + $(window).height() - element_top) + "px)";
             $(this).css({height: bg_height,"-webkit-transform": main_position,"-moz-transform": main_position,"-ms-transform": main_position,transform: main_position});
           }
        });
    });

  }
});
</script>

 

BOOM. You’re done! Simple hey?

What it does

Pretty simple really:
1) Checks and only applies the code if you’re viewing the page on a mobile device – As it performs this check using the same code as Divi, it means it will not interfere with the standard Divi desktop parallax code.
2) Checks each parallax element on your page to see if they are visible to the end-user on the screen (i.e. are in the viewport) and only applies the parallax effect if they are
3) Uses the same formulas Divi uses for it’s desktop parallax

The hard part was digging through the Divi theme code to find the original parallax calculations and simplifying it…

True Parallax vs CSS Parallax

Divi gives you two options for Parallax backgrounds: CSS Parallax and True Parallax.

On mobile devices, CSS Parallax will not work as it requires a CSS property ‘background-attachment:fixed’ to be set, which is not supported on most mobile devices/browsers.

Therefore, the code applies True Parallax to all parallax sections on mobile, regardless of whether they are set at CSS Parallax or True Parallax.

Use the Divi Visual Builder as normal to set up your parallax backgrounds, then this code automatically makes them they work on mobile too.

Demo

Below is a section added using the normal Divi Builder with a background image set and ‘use parallax’ selected. As mentioned, it doesn’t matter whether you choose CSS or True Parallax, the effect will be the same on mobile.

This section was created using the Divi Builder and has a Parallax background image set. Bingo, it now works on mobile!

Rounding up

So there you have it, a simple bit of JQuery and all your Divi parallax sections are now working beautifully on mobile devices 🙂

Please leave a comment if you found this quick tutorial useful!

About the Author

Divi Hype - Ed Solman Avatar Large

Ed Solman

Entrepreneur, Blogger and Website Developer/Designer. Passionate about helping people and businesses develop and grow. Daredevil sportsbike enthusiast.

Divi Hype favicon light

Get the Hype

Join our mailing list for all the latest Hype and get our massive Freebie bundle, with all our Custom module layouts and the HyperChild plugin for FREE!

You have Successfully Subscribed!