Hi,
I've just bought the Simply Javascript book, and I'm absolutely thrilled with it - and with writing object oriented javascript![]()
I've tried to replicate the "clickable area" function used on http://www.vivabit.com/atmedia2007/ by using the principles of this book, and I would be most grateful if I could possibly get some feedback on my very short script. Does it seem sensible?
The idea is to grab the first url in every div element that has an "area" classname, and make the whole div element clickable. There's also an "over" class which changes the appearence of the element.
Thanks,
Pøbel
Result: http://nystad.net/pobel/
Code JavaScript:var clickArea = { init: function() { var area = Core.getElementsByClass("area"); for (i = 0; i < area.length; i++) { Core.addEventListener(area[i], "click", clickArea.mClick); Core.addEventListener(area[i], "mouseover", clickArea.mOver); Core.addEventListener(area[i], "mouseout", clickArea.mOut); } }, mClick: function() { var link = this.getElementsByTagName('a')[0].href; location.href = link; }, mOver: function() { Core.addClass(this, "over"); }, mOut: function() { if (Core.hasClass(this, "over")) { Core.removeClass(this, "over"); } } }; Core.start(clickArea);





Bookmarks