Results 1 to 4 of 4

Thread: Putting random full screen images in a Div in IE 11 with JavaScript

  1. #1
    Join Date
    Nov 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Putting random full screen images in a Div in IE 11 with JavaScript

    My agency is transitioning from I.E. 8 to I.E. 11 in the near future. The main page of our website features four random full-screen background images that automatically change on the first of each month. (I received some excellent assistance from this forum getting the syntax of the style filter in that code to function correctly so many thanks for that.)

    The following JavaScript and CSS code works very well in I.E. 8 but will not work in I.E. 11. I have made a number of attempts to modify the code using CSS3 background-size properties "cover" or "contain" but have had no luck getting the images to display in I.E. 11 so there is clearly something I am missing. My initial question is, can this code be tweaked to work in I.E. 11 or should I scrap this approach and go with something different? My secondary question is, if this approach can work, are there any suggestions on how it can be tweaked? Thanks

    NOTE: The code only reflects one month. There are additional "else if" sections for each month but the code is identical.

    Code:
    var year = new Date();
    var month = year.getMonth(); 
    
    if(month == 0)
    {
    var imgCount = 4;
            var dir = 'images/background_photos/01_Jan_Full/';
            var randomCount = Math.round(Math.random() * (imgCount - 1)) + 1;
            var images = new Array
                    images[1] = "image1.jpg", 
                    images[2] = "image2.jpg", 
                    images[3] = "image3.jpg", 
    		images[4] = "image4.jpg", 
    document.getElementById("container").style.filter =
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + dir + images[randomCount] + "', sizingMethod='scale')";
    }
    
    Style for the container Div
    
    #container    
    {
    position: fixed; 
    margin: 0;
    background-repeat: no-repeat;
    background-position: center center;
    width: 100%;
    height: 100%;
    }
    Last edited by james438; 12-11-2015 at 04:47 AM. Reason: format

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Untested, but try replacing;
    Code:
    document.getElementById("container").style.filter =
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + dir + images[randomCount] + "', sizingMethod='scale')";
    with
    Code:
    document.getElementById("container").style.backgroundImage = "url('" + dir + images[randomCount] + "')";
    and then add background-size:cover; to the CSS
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Quote Originally Posted by Danl0013 View Post
    My agency is transitioning from I.E. 8 to I.E. 11 in the near future.
    .
    .
    ... however, the rest of the world may not be, so you need to cater for those people as well as the large proportion of the world's population who steer clear of anything to do with Mickey$0ft,

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Code:
    document.getElementById("container").style.backgroundImage = "url('" + dir + images[randomCount] + "')";
    with background-size:cover; in the CSS will suit IE9+ and all other modern browsers.

    Current browser usage for IE8 and less is 2.13% and falling (http://www.sitepoint.com/browser-tre...refoxs-future/) so its probably OK to drop support for those older browsers altogether. Check your website usage though (Google Analytics or whatever web stats tool you use) - you may have more users, or you may have less, so its up to you to decide how worthwhile it is (and how much extra dev effort you want to put in). If the background image is just for decoration, I would personally discontinue support for it in IE8 now - as long as your users can still read the critical content, that's the main thing.

    If you need further help, please post a link to your page.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. Replies: 6
    Last Post: 01-23-2015, 11:54 AM
  2. Putting a random image in a Div with JavaScript
    By Danl0013 in forum JavaScript
    Replies: 3
    Last Post: 12-03-2014, 09:58 PM
  3. Replies: 12
    Last Post: 01-25-2009, 04:57 PM
  4. Making current window full-screen using JavaScript
    By codeexploiter in forum JavaScript
    Replies: 1
    Last Post: 09-07-2007, 09:02 AM
  5. Full-Screen Pop-Up.
    By Moglizorz in forum HTML
    Replies: 5
    Last Post: 04-22-2007, 01:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •