Witam

Jeśli na jego obszar najedzie się myszką funkcja powoduje podświetlenie na zielono diva. Obecnie mam 3 divy "myElement".

Czy da się z tych 3 identycznych funkcji zrobic jedną porawnie funkcjonującą? Tak, aby powstała klasa, którą można wszedzie stosowac a nie ID danego diva.


  1. window.addEvent('domready', function(){
  2.  
  3. var el = $('myElement'),
  4. color = el.getStyle('backgroundColor');
  5.  
  6. // We are setting the opacity of the element to 0.5 and adding two events
  7. $('myElement').set('opacity', 0.8).addEvents({
  8. mouseenter: function(){
  9. // This morphes the opacity and backgroundColor
  10. this.morph({
  11. 'opacity': 1,
  12. 'background-color': '#c6d880'
  13. });
  14. },
  15. mouseleave: function(){
  16. // Morphes back to the original style
  17. this.morph({
  18. opacity: 0.7,
  19. backgroundColor: color
  20. });
  21. }
  22. });});
  23. window.addEvent('domready', function(){
  24. var el = $('myElement2'),
  25. color = el.getStyle('backgroundColor');
  26.  
  27. // We are setting the opacity of the element to 0.5 and adding two events
  28. $('myElement2').set('opacity', 0.8).addEvents({
  29. mouseenter: function(){
  30. // This morphes the opacity and backgroundColor
  31. this.morph({
  32. 'opacity': 1,
  33. 'background-color': '#c6d880'
  34. });
  35. },
  36. mouseleave: function(){
  37. // Morphes back to the original style
  38. this.morph({
  39. opacity: 0.7,
  40. backgroundColor: color
  41. });
  42. }
  43. });});
  44. window.addEvent('domready', function(){
  45. var el = $('myElement3'),
  46. color = el.getStyle('backgroundColor');
  47.  
  48. // We are setting the opacity of the element to 0.5 and adding two events
  49. $('myElement3').set('opacity', 0.8).addEvents({
  50. mouseenter: function(){
  51. // This morphes the opacity and backgroundColor
  52. this.morph({
  53. 'opacity': 1,
  54. 'background-color': '#c6d880'
  55. });
  56. },
  57. mouseleave: function(){
  58. // Morphes back to the original style
  59. this.morph({
  60. opacity: 0.7,
  61. backgroundColor: color
  62. });
  63. }
  64. });});