Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active April 27, 2018 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullDev/2079c8cfbb0922a921856c4d19b249d4 to your computer and use it in GitHub Desktop.
Save NullDev/2079c8cfbb0922a921856c4d19b249d4 to your computer and use it in GitHub Desktop.
Visual Composer iPad height fix

This is a (temporary fix) for visual composer messing up heights of grid elements on iPads.
Basically, visualcomposer just parses the device width and height very sloppy.
this results in a height property like this:

element {
    height: 314x301;
}

which is of course wrong.

This code is a fix for that.
It first waits until the visual composer element exists, and the extracts the height and fixes it.

if (navigator.userAgent.match(/iPad/i) != null){
    var element = ".vc_custom_1234567890000"; //change this here
    var checkExist = setInterval(function(){
       if ($(element).length){
          clearInterval(checkExist);
          var height = $(element).attr("style").split('height:').pop().split(';').shift();
          var fixed = height.substr(height.indexOf("x") + 1);
          $(element).attr("style", "height:" + fixed + "px !important;");
       }
    }, 100);
}

Additionally, if the text inside the VC Element is too big, it can be optimized using this JS code:

var textsel = ".vc_gitem-zone-mini .vc_gitem-row-position-bottom .vc_custom_heading h3";
$(textsel).addClass("ipad--fix");

inside

var checkExist = setInterval(function() { /* ... */ }, 100);

with those CSS rule:

.ipad--fix { font-size: 17px !important; /* or any other value */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment