SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast kidwizdumb's Avatar
    Join Date
    Oct 2003
    Location
    Ojai
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Swapping Background Image w/ DOM

    Hi all,

    at work here today...trying to think of some easy way to do a navigation with images that swap out using CSS, rather than document.images.

    This has been my approach so far, and isn't working yet. I'm looking for something that would work well in NS6/7 and IE5.5/6:

    Code:
    function swapBackground(el,fn) {
    	obj = document.getElementById(el);
    	switch (fn) {
    		case 'set':
    			obj.setAttribute("style", "background-image: url(images/back_gradient.gif);");
    			break;
    		case 'reset':
    			obj.setAttribute("style", "background-image: none;");
    	}
    }
    I know that drop-downs would be really complex, but is this easy enough, or will this take like hours to code?

  2. #2
    SitePoint Enthusiast kidwizdumb's Avatar
    Join Date
    Oct 2003
    Location
    Ojai
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry about the code pushing the window out like that..

  3. #3
    SitePoint Enthusiast kidwizdumb's Avatar
    Join Date
    Oct 2003
    Location
    Ojai
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, i seem to have gotten somewhere with this, and it works in IE/Mozilla rather well.

    Let me know if you think of anything

    Code:
    function swapBackground(el,fn) {
    	obj = document.getElementById(el);
    	switch (fn) {
    		case 'set':
    			obj.style.backgroundImage = "none";
    			break;
    		case 'reset':
    			obj.style.backgroundImage = "url(images/back_gradient.gif)";
    	}
    }

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now you've got it

    looks good


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
  •