Search code examples
htmlcssmobile-safari

Enable Parralax effect on Laptops and Desktops only?


Is there any way to only trigger the Parralax effect on laptop and desktop views?

Atm I have the following however, it doesn't allow an image to be displayed on some device browsers: Safari to be specific.

.parralax {

/* Full height */
height: 100%; 

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

My HTML solely references this in the section I want the Parralax effect.

<section id="home" class="home parralax bg-img fix">

Solution

  • Make sure you put your external style sheet first in the document so it overwrites your parallax rules.

    /*Mobile 480px*/
    /*Desktop 992px*/
    /*Huge 1280px*/
    
    @media screen and (min-width: 480px) and (min-width: 768px), (min-width: 992px), (min-width: 1280px) {
    .parralax {
       /* Full height */
       height: 100%; 
    
       /* Create the parallax scrolling effect */
       background-attachment: fixed;
       background-position: center;
       background-repeat: no-repeat;
       background-size: cover;
     }
    }