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.
window.addEvent('domready', function(){ var el = $('myElement'), color = el.getStyle('backgroundColor'); // We are setting the opacity of the element to 0.5 and adding two events $('myElement').set('opacity', 0.8).addEvents({ mouseenter: function(){ // This morphes the opacity and backgroundColor this.morph({ 'opacity': 1, 'background-color': '#c6d880' }); }, mouseleave: function(){ // Morphes back to the original style this.morph({ opacity: 0.7, backgroundColor: color }); } });}); window.addEvent('domready', function(){ var el = $('myElement2'), color = el.getStyle('backgroundColor'); // We are setting the opacity of the element to 0.5 and adding two events $('myElement2').set('opacity', 0.8).addEvents({ mouseenter: function(){ // This morphes the opacity and backgroundColor this.morph({ 'opacity': 1, 'background-color': '#c6d880' }); }, mouseleave: function(){ // Morphes back to the original style this.morph({ opacity: 0.7, backgroundColor: color }); } });}); window.addEvent('domready', function(){ var el = $('myElement3'), color = el.getStyle('backgroundColor'); // We are setting the opacity of the element to 0.5 and adding two events $('myElement3').set('opacity', 0.8).addEvents({ mouseenter: function(){ // This morphes the opacity and backgroundColor this.morph({ 'opacity': 1, 'background-color': '#c6d880' }); }, mouseleave: function(){ // Morphes back to the original style this.morph({ opacity: 0.7, backgroundColor: color }); } });});