Reputation: 2784
I have a couple of problems regarding background images in Safari on ios (iPad/iPhone). Everything works fine on regular browsers. The image is supposed to be fixed and fill the screen.
Here is my html
<html>
<head>
Some head stuff
</head>
<body>
<div class="pagewrap">
<header class="header">
<div class="menu">
Some header stuff
</div>
</header>
<div class="full-page-background fullheight"></div>
<div class="wrap">
<div class="main">
Some content
</div>
</div>
<aside class="sidebar">
<nav class="mobnav">
My mobile nav
</nav>
</aside>
</div>
<div class="custom-background">
A placeholder for a custom background image
</div>
</body>
</html>
Here is the css for .full-page-background
.full-page-background {
background: url(/Content/Vixen/img/background02.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:top center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: fixed;
width: 100%;
z-index: 1;
}
Here is the js for .fullheight to make sure it fills the height of the browser window.
$(document).ready(function() {
var bodyheight = window.innerHeight ? window.innerHeight:$(window).height();
$(".fullheight").height(bodyheight);
});
// for the window resize
$(window).resize(function() {
var bodyheight = window.innerHeight ? window.innerHeight:$(window).height();
$(".fullheight").height(bodyheight);
});
Here is the js for .custom-background - if there is a image in the div (placed by the user in the cms) it switches the default image for the new one. Works well on desktop but does nothing on ios-safari.
$(".background-image").each(function() {
imgsrc = this.src;
$('.full-page-background').css({
background:'url(' + imgsrc +') no-repeat fixed center center / cover transparent'
});
});
Upvotes: 1
Views: 9131
Reputation: 2784
I found this plugin here:
http://srobbin.com/jquery-plugins/backstretch/
It seems to work well for full-size background images on all devices (all that I have tested that is!). Which includes Safari on ios.
Upvotes: 1