User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 426,203 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,850 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3697 | Replies: 7
Reply
Join Date: Sep 2004
Posts: 33
Reputation: anthmaina is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
anthmaina anthmaina is offline Offline
Light Poster

Question Drop down menu with images

  #1  
Jun 18th, 2007
I have written a script for a drop down menu on my site which on mouse over the menu item changes from blue to yellow and show the drop down item but now I'm stuck,i want to use background images instead of colors.On mouse over, it changes from image A to image B and still show drop down items.Any clue or suggestions?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Drop down menu with images

  #2  
Jun 18th, 2007
i dont believe javascript holds a method to directly change a css background. but if you create two css classes for your menus you can use javascript to change the class. just google search for altering a css class from javascript im sure theres a few examples. An easier way tho perhaps could be a purely css menu ? try googling that aswell as they can be used by all clients unlike javascript. but this depends if you want a drop down with inner dropdown groups. But yer try having a look and see waht suits you.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,858
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Drop down menu with images

  #3  
Jun 18th, 2007
I have written a script for a drop down menu on my site which on mouse over the menu item changes from blue to yellow and show the drop down item but now I'm stuck,i want to use background images instead of colors.On mouse over, it changes from image A to image B and still show drop down items.Any clue or suggestions?
Maybe pasting your code here would help us provide some concrete suggestions.

> i dont believe javascript holds a method to directly change a css background
Something like this:
  1. <html>
  2. <head>
  3. <script>
  4. function changeOver(id)
  5. {
  6. var elem = document.getElementById(id);
  7. elem.style.backgroundColor = '#aabbcc';
  8. elem.style.cursor = 'pointer';
  9. elem.style.cursor = 'hand';
  10. }
  11. function changeOut(id)
  12. {
  13. document.getElementById(id).style.backgroundColor = '#ffffff';
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <span id="myP" onmouseout="changeOut(this.id);" onmouseover="changeOver(this.id);">Place your mouse over this text</span>
  19. </body>
  20. </html>
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Drop down menu with images

  #4  
Jun 18th, 2007
Originally Posted by ~s.o.s~ View Post
Maybe pasting your code here would help us provide some concrete suggestions.

> i dont believe javascript holds a method to directly change a css background
Something like this:
  1. <html>
  2. <head>
  3. <script>
  4. function changeOver(id)
  5. {
  6. var elem = document.getElementById(id);
  7. elem.style.backgroundColor = '#aabbcc';
  8. elem.style.cursor = 'pointer';
  9. elem.style.cursor = 'hand';
  10. }
  11. function changeOut(id)
  12. {
  13. document.getElementById(id).style.backgroundColor = '#ffffff';
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <span id="myP" onmouseout="changeOut(this.id);" onmouseover="changeOver(this.id);">Place your mouse over this text</span>
  19. </body>
  20. </html>


sorry what i meant was i dont believe you can change a background image via javascript. my bad
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,858
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Drop down menu with images

  #5  
Jun 18th, 2007
> sorry what i meant was i dont believe you can change a
> background image via javascript. my bad

Something like this;
  1. <html>
  2. <head>
  3. <script>
  4. function changeOver(id)
  5. {
  6. var elem = document.getElementById(id);
  7. elem.style.backgroundImage = "url(submit.gif)";
  8. elem.style.cursor = 'pointer';
  9. elem.style.cursor = 'hand';
  10. }
  11. function changeOut(id)
  12. {
  13. var elem = document.getElementById(id);
  14. elem.style.backgroundImage = "url(search.gif)";
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <span style="background-image: url(search.gif); color: white;" id="myP" onmouseout="changeOut(this.id);" onmouseover="changeOver(this.id);">
  20. Hello to all of you. This text is white
  21. </span>
  22. </body>
  23. </html>
Attached Images
File Type: gif search.gif (950 Bytes, 31 views)
File Type: gif submit.gif (2.9 KB, 30 views)
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Drop down menu with images

  #6  
Jun 19th, 2007
you obviously have magical powers of which i do not.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,858
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Drop down menu with images

  #7  
Jun 19th, 2007
> you obviously have magical powers of which i do not.
Nah, I just like poking at things. ;-)
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jun 2007
Posts: 1
Reputation: butjeffsays is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
butjeffsays butjeffsays is offline Offline
Newbie Poster

Re: Drop down menu with images

  #8  
Jun 19th, 2007
You could save yourself some scripting next time with purely css rollovers, and save the scripting for the dropdown positioning.

Try one of the image rollover lists:

http://css.maxdesign.com.au/listamatic/
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 7:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC