Many corporate websites make use of this content-changing mechanism to bring a new level of professionalism to their front pages.
Launching off our previous recipe, we add a new level of interaction. Prepare both the mouseover and mouseout Element.addEvents()
code blocks, as well as three images to use for the new DOM element that will be updated when our button listeners are fired. This screenshot shows how the lady figurine appears when the Witch button is moused over:
The mouseover action is adjusted with a new line of code that uses the button/image naming structure to update the background style properties of the DOM element pic
.
... 'mouseover':function() { this.setStyles({'color':'#FFF', 'background-position':'bottom'}); var txt = this.get('text'); this.set('text',text_changer(txt)); $('pic').setStyle('background','#FFF url(07_'+txt+'.jpg) no-repeat top left'); }, ...