Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorNickName
    • CommentTimeMay 17th 2010
     permalink
    Hallo to everyone!

    I got no experience with JS, but i managed to scrumble this.


    Code -- >

    if ((screen.width<=800) && (screen.height<=600)) {
    document.getElementById('bg').style.display='none';
    document.write('<style type="text/css">body{background: white url(images/bg/i4.jpg);}"></style>')
    }
    if ((screen.width<=1024) && (screen.height>600 && screen.height<800)) {
    document.getElementById('bg').style.display='none';
    document.write('<style type="text/css">body{background: white url(images/bg/i3.jpg);}"></style>')
    }
    if (screen.width<=1280 && (screen.height>=800 && screen.height<900)) {
    document.getElementById('bg').style.display='none';
    document.write('<style type="text/css">body{background: white url(images/bg/i2.jpg);}"></style>')
    }
    if (screen.width<=1280 && (screen.height>=900 && screen.height<=1100)) {
    document.getElementById('bg').style.display='none';
    document.write('<style type="text/css">body{background: white url(images/bg/i1.jpg);}"></style>')
    }
    document.write('<style type="text/css">body{background-attachment: fixed; background-position:center;}"></style>');

    <-- Code


    I do know it is bulky, but I can't do any better, if anyone can advice shorter vesrion, that be great!

    Oh, and for those who has JS disabled or fall out of this script reach, get 100% streched <img> with id "bg"!


    I also want JS to able to change the background image (user end), play the above script again and run function that will recognize image's name and place description text (in div for example) accordingly. How difficult is that and can anyone drop some lines of code here? Thanks in advance!
    • CommentAuthorJaneck
    • CommentTimeMay 26th 2010
     permalink
    I would recommend adjusting a div's classes instead.


    onLoad(function(){
    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;
    if ((width<=800) && (height<=600)) {
    $("element").className = "layout1" ;
    });

    Judging by your code I will assume that you don't know what onLoad is or $
    I would strongly suggest you look up prototype or jquery and get used to $ selector and onLoad ( window.ready i believe for jquery)
Add your comments
    Username Password
  • Format comments as (Help)