Workaround for 'background-attachment: fixed' which is not working in iOS4

前端 未结 2 1468
孤街浪徒
孤街浪徒 2021-01-19 01:05

I\'m struggling to get web page with a fixed background image, so the image does not move when page is scrolled in a UIWebView.
What I\'ve discovered is: backgroun

相关标签:
2条回答
  • 2021-01-19 01:33

    Use a div for the background with a negative z-index:

    <head>
    <style>
    #background {
        background: url("background.jpg") no-repeat;
        position: fixed;
        top: 0;
        left: 0;
        background-size: 320px 480px;
        width: 320px;
        height: 480px;
        z-index: -1;
    }
    </style>
    </head>
    
    <body>
    <div id="background"></div>
    
    This body text appears over the fixed background and scrolls.
    
    </body>
    

    Works on iOS 5 and iOS 6.

    0 讨论(0)
  • 2021-01-19 01:38

    I am not sure what is going on with the CSS and have not had a chance to check it out for myself but I know when I was trying to get rid of the shadows from a UIWebView I used this bit of code:

    NSArray *sv = [NSArray arrayWithArray:[myWebView subviews]];
    UIScrollView *webScroller = (UIScrollView *)[sv objectAtIndex:0];
    
    NSArray *wsv = [NSArray arrayWithArray:[webScroller subviews]];
    
    [[wsv objectAtIndex:6] setHidden:YES];
    [[wsv objectAtIndex:7] setHidden:YES];
    [[wsv objectAtIndex:8] setHidden:YES];
    [[wsv objectAtIndex:9] setHidden:YES]; 
    

    and it got rid of the shadows. I thought I got the answer off of a SO question but when I looked for it this is the only one that came up.

    It passed App Store inspection.

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