background attachment: fixed not working on android/ios

前端 未结 4 1442
暗喜
暗喜 2021-01-07 01:44

This is my code:

相关标签:
4条回答
  • 2021-01-07 02:15

    bacground-attachment:fixed;

     .fixed { 
        background: url(img/kid1/1.jpg) no-repeat center center;
        background-attachment:fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        }
    
    0 讨论(0)
  • 2021-01-07 02:18

    background-attachment: fixed is not supported on many mobile phone browsers.

    If you check here: http://caniuse.com/#feat=background-attachment, you'll see the reason why on your laptop you get a different result that the one from your phone.

    So far, I've found that the best thing to do is treat the image on phones as an image without parallax.

    hope it helps

    0 讨论(0)
  • 2021-01-07 02:26

    Div cover (version 1):

    HTML5:

    <div class="fixed"></div>
    

    CSS3:

    .fixed { 
    background: url(img/kid1/1.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    }
    

    OR:

    Div cover (version 2):

    HTML5:

    <div class="fixed" style="background: url(img/kid1/1.jpg) no-repeat center center fixed;"></div>
    

    CSS3:

    .fixed {  
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    }
    

    Or on "html" tag (fullscreen cover):

    html { 
    background: url(img/kid1/1.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    }
    

    Simple. :)

    0 讨论(0)
  • 2021-01-07 02:36

    To parallax properly on mobile use perspective. Parallaxing with JS or background-attachment:fixed; doesn't work properly on mobiles.

    https://developers.google.com/web/updates/2016/12/performant-parallaxing

    0 讨论(0)
提交回复
热议问题