views:

698

answers:

2

Okay, so I have a site running Joomla and it is using the mootools 1.11 framework. I've fudged together a working version of this using examples from the mootools 1.2 framework but cannot get the two to co-exist even with the compatibility layer, without breaking other modules in the Joomla site.

Question I have a couple of divs with a class of ".box_panel" and I have it so that they on mouseover they go from 50% opacity and back to 100% opacity on mouseleave. The problem I'm having is what is the code to set them to 50% onload?

In mootools 1.2 I used:

<body onload="$$('div.box_panel').fade(0.5);">

The code I'm using for the mouseover/mouseleave effects is:

window.addEvent('domready',function() { 
    //first, apply a class to each of your menu element
    //$$('.links') puts every element wearing the .links class into an array
    //$$('.links').each is to browse the array an apply a funtion to... each of them
    $$('.box_panel').each(function(el, i) {
     //there comes exactly your former fx statement except for
     var ExampleFx = new Fx.Style(el, 'opacity', { //the fact i apply the effect on el
      wait: false, //and wait: false which make the effect not waiting (very useful on the mouseout or mouseleave function...
      opacity: 0.5,
      duration: 500,
      transition: Fx.Transitions.Quart.easeInOut
     });
     //and there i apply (always on el) the effect on mouseenter (similar in this case but often better than mouseover)
     //and mouseleave (same for mouseenter but concerning mouesout)
     el.addEvent('mouseleave', function() { ExampleFx.start(1, 0.5); });
     el.addEvent('mouseenter', function() { ExampleFx.start(0.5, 1); });

    });
});
+2  A: 

Can you not just add ExampleFx.start(1, 0.5); before the last brackets (after the $$('.box_panel')... statement)?

Mladen Mihajlovic
Thanks for this I'll give it a try.
I tried after the statement like below without success:$$('.box_panel').each(function(el, i) {ExampleFx.start(1, 0.5); Thinking about it I could just use CSS properties to set the starting opacity of the .box_panel.
A: 

Simple:

$$('.box_panel').effect('opacity', 0.5);
// run this right after your window.addEvent('domready', function() {

Edit: I were a bit wrong here. Mladen Mihajlovic answered completly correct. Also, here are some links for you:

moff