I have a website that I have added some basic Mootools animation to. Here is the page of the website i have a question on:
http://www.humsdrums.com/portfolio/webdesign.html
You will notice that when you mouse over the large images, they fade and a magnifying glass tweens down. Here is the Mootools class called "Magnify" I made for this:
var Magnify = new Class({
Implements : [Options, Events],
options : {
},
initialize : function (item, image, options)
{
this.setOptions(options);
this.div = document.id(item);
this.img = $$(image);
this.tweenBackground = new Fx.Tween(this.div,{
duration:'250',
property:'background-position'
});
this.div.addEvent('mouseenter', this.reveal.bind(this));
this.div.addEvent('mouseleave', this.hide.bind(this));
},
reveal : function()
{
this.tweenBackground.cancel();
this.tweenBackground.start('175px -78px', '175px 90px');
this.img.tween('opacity', .15);
console.log('mouse over');
},
hide :function ()
{
this.tweenBackground.cancel();
this.tweenBackground.start('175px 90px', '175px -78px');
this.img.tween('opacity', 1);
}
});
I then need to initialize an instance of the class for each element i want to do this by grabbing the css id.
window.addEvent('domready', function()
{
var magnify1 = new Magnify('p1', '#p1 img');
var magnify2 = new Magnify('p2', '#p2 img');
var magnify3 = new Magnify('p3', '#p3 img');
var magnify4 = new Magnify('p4', '#p4 img');
});
What I want to be able to do is simple give each element I want to have this functionality a CSS class of "magnify so I don't have to use individual ID's and add another instance of the Mootools class every time.
If I the element a CSS class and put it into my Mootools class, it breaks. Even if it didn't break, it seems like Mootools would simply make all elements with that CSS class animate at the same time when only one is moused over.
How would I detect which instance of the "magnify CSS class is being moused over? My only thoughts were to find a way to grab all the elements with the "magnify" CSS class, put them into an array and then check to see if the item being hovered over equals one of the items in the array. I don't know how to do that or if that is the best way.
Any help or suggestions would be great! Let me know if you want to see more code or if I can explain something better.