FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

JS Help Needed...

 


Gushe
Hello all! Smile
I'm learning JS now.. And I'm planning to do CSS after Smile And I'll hope I'll be able to be helpfull to you one day too Wink but now I have a question.

I'm working on my First Javascript.. Or what you call "script", It's sort off layout changer for a very basic Avatar: Tha Last Airbender Fansite; which is made by a 14y old girl; so it's really basic Razz And the "Layout" is more like a background image; with some Iframes with some content. Smile

And The Layout changer is very simple infact; it just changes the background image Smile
My plan was actually the following:

- somewhere on the site there is an Iframe which holds the Lay changer
- In that frame there are little preview pics of the other layouts; If you hold your mouse cursor on a preview picture; Tha background image changes; but when you get your cursor off the preview pic it returns to the original layout.
- If you click on the picture; the new layout stays for as long as you are on the site. Smile


So thats the basic idea. Smile

now; I already wrote some code; Which I thought was quite ok; but I don't know if all things will work; And I just realized I forgot something:
- I wrote tha script that chen you hold your mouse over it; it changes and when you get off your cursor it changes back to normal and when you click it it changes too; but when you get off your mouse when you clicked; it will still return to normal; because I think it counts as an Mouseoff event.. Razz
And I don't know how to do it with more layouts.. Razz

Here is the code I wrote:

Code:

<script type="text/javascript">

// the 2 background image links
var emberlay = "http://i7.tinypic.com/82mx74j.jpg"
var desertlay = "http://i16.tinypic.com/82vhw00.jpg"

//the function to change into the second layout
function DesertChange()
  {
  document.getElementById("Layout").src=desertlay
  }

// the function to change into the first layout again (when you are temp on the second layout)
function EmberChange()
  {
  document.getElementById("Layout").src=emberlay
  }

// the function to return to the layout you had before holding your mouse over the image
function OrigLay()
  {
   if (document.getElementById("Layout").src == emberlay)
   {
      DesertChange()
   }

   else
   {
   EmberChange()
   }
}
</script>



And this is what you add to the HTML page:

Code:

add id="layout" to background image
add onclick="Desertchange()" to the layout preview image
add onMouseOver="Desertchange()" to the layout preview image
add onMouseOut="OrigLay()" to the layout preview image


Now I have the following questions:

- Is this code valid JS? (like if the links as variables will work?)
- How to Get the idea i posted befire (with the clicking thingy)
- How should the OrigLay() funtion be to do this with 3 or 4 layout images?

Or does anyone have other remarks? Smile


thanx in advance!
~Gushe Wink
Gushe
Anyone here..? Smile



~Gushe
Aredon
Apparently "Layout" is the ID (or it could also be a NAME if you are using Internet Explorer) of an IMG tag...
You should really be using a DIV and CSS's background-image property.

Code:

<style type="text/css">
.ember{
background-image:url(http://i7.tinypic.com/82mx74j.jpg);
width:1000px; height:633px;
}
.desert{
background-image:url(http://i16.tinypic.com/82vhw00.jpg);
width:1000px; height:590px;
}
.nextone{
background:white;
width:1000px; height:600px;
}
</style>

Then instead of using an IMG tag use a <div id="LayoutDIV" class="ember">...</div> and change its class dynamically with JavaScript:
Code:

<script type="text/javascript">
layouts=new Array("ember","desert","nextone");
layoutindexes=new Object();for(i=0;i<layouts.length;i++)layoutindexes[layouts[i]]=i;

function nextLayout(){
var i=layoutindexes[document.getElementById("LayoutDIV").className]+1;if(i>=layouts.length)i=0;
document.getElementById("LayoutDIV").className=layouts[i];
}

function previousLayout(){
var i=layoutindexes[document.getElementById("LayoutDIV").className]-1;if(i<0)i=layouts.length-1;
document.getElementById("LayoutDIV").className=layouts[i];
}
</script>
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.