www.webdeveloper.com
Results 1 to 2 of 2

Thread: getting backgroundImage for image changer..

  1. #1
    Join Date
    Mar 2005
    Location
    planet earth
    Posts
    121

    Question getting backgroundImage for image changer..

    hi, this will seem a little nooby, but..i'm trying to use a mobile friendly (i.e. non flash) image changer using js?


    this works in chrome and safari, but not opera, ie or ff? grr!

    http://tigerbaydesign.co.uk/imagech.html

    i'm thinking it's tied up with getting the backgroundImage first because i know all browsers are getting inside the action braces..

    you can view source or look at this:

    HTML Code:
    <title>image change test</title>
    <link href="imagech.css" rel="stylesheet" type="text/css" />
    <script>
    function changeImage(action)
    {
    	obj=document.getElementById('mainimg');
    	if(obj.currentStyle) eimg=obj.currentStyle.backgroundImage;
    	else eimg=getComputedStyle(obj,'').getPropertyValue('background-image');
    	
    	if (action=="prev") {
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_01.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_05.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_02.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_01.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_03.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_02.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_04.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_03.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_05.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_04.jpg')"; var eimg=0; };
    	}
    	if (action=="next") {
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_01.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_02.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_02.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_03.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_03.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_04.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_04.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_05.jpg')"; var eimg=0; };
    		if (eimg=='url(http://tigerbaydesign.co.uk/tb_images/intro_05.jpg)') { mainimg.style.backgroundImage="url('tb_images/intro_01.jpg')"; var eimg=0; };
    	}
    }
    </script>
    </head>
    <body>
    <div id="mainimg">
    <div id="prevb"><a href="javascript:changeImage('prev')">previous</a></div>
    <div id="nextb"><a href="javascript:changeImage('next')">next</a></div>
    </div>
    
    </body>
    what am i doing wrong?!

    captain, i've spotted an M-class planet!

    http://eupeople.net/forum

  2. #2
    Join Date
    Mar 2005
    Location
    planet earth
    Posts
    121

    Exclamation

    solved this! please ignore
    captain, i've spotted an M-class planet!

    http://eupeople.net/forum

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles