Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

How to make background image responsive for ipad phone ie

I am using the script below to for random background images.
 I am also using a css class which successfully make normal (non-background images) responsive.
I want to know a way to make the random background images responsive to display size eg IE, ipad, smartphone. At moment they cover smaller display but distorted and IE shows up as fixed in left top.
Thanks in advance and anticipation .

<script type="text/javascript">
var totalCount = 5;
function ChangeIt()
{
var num = Math.ceil( Math.random() * totalCount );
document.body.background = 'bgimages/'+num+'.jpg';
document.body.style.backgroundSize = '100% 100%';
document.body.style.backgroundRepeat = "no-repeat";
document.body.style.backgroundAttachment="fixed";
// Background repeat
}
</script>
0
LeighJor
Asked:
LeighJor
1 Solution
 
GaryCommented:
Try
document.body.style.backgroundSize = 'cover';

How it looks/scales will depend on the image size to begin with
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now