1

I've recently been asked to work on a few websites. One of these websites wants to be "more interactive" and they showed me a site they would like to emulate.

I'm not very good with writing my own scripts, especially with regards to DHTML, so I use MooTools to deal with the more interface-y changes.

In my HTML code I have two Div tags, and I want for it to happen that when you mouseover one, it shrinks the other one and expands the one you're looking at, but no events that I try to attach are firing at all (nothing happens, and nothing appears in the console).

Here is my HTML, I am just using the stock mootools downloaded from their website.

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Cnergi - Splash </title>
        <link rel="stylesheet" href="main.css" type="text/css" />
        <script type="text/javascript" src="mootools.js"></script>
        <script type="text/javascript">
            document.addEvent('domready',function(){

                $('employee').set('opacity', 0.5).addEvents({
                    mouseenter: function(){
                      // This morphes the opacity and backgroundColor
                      this.morph({
                        'opacity': 0.6,
                        'background-color': '#E79D35'
                      });
                    },
                    mouseleave: function(){
                      // Morphes back to the original style
                      this.morph({
                        opacity: 0.5,
                        backgroundColor: color
                      });
                    }
                  });

            });
        </script>
    </head>
    <body>
        <div id="wrapper">

            <div class="employee" id="employee">
                Employee test
            </div>
            <div class="client" id="client">
                Client Test
            </div>

        </div>
    </body>
</html>

Further Description of Problem

Basically, if I call the morph straight from the 'domready' function, it works, but the event calls that are supposed to come from the mouseenter (also tried mouseover, and even click. none work) never happen. No errors are being thrown. I am honestly befuddled, I've never had this problem before.

Any ideas?

EDIT

Currently attempting this code, still nothing shows up.

<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        <link rel="stylesheet" href="main.css" type="text/css" />
        <script type="text/javascript" src="mootools.js"></script>

    </head>
    <body>
        <div id="wrapper">
            <div id="employee" class="employee">
                Something
            </div>
        </div>
        <script type="text/javascript">
            document.addEvent('domready',function(){

                var s = $('employee');
                s.addEvent('click',function(){
                    alert('I was clicked!');
                });

            });//End document.addEvent domready
        </script>
    </body>
</html>

EDIT 2

Has something to do with my stylesheet declaration; if I remove it, the events fire as they should.

It's actually appears to be any styling at all. The moment I put a tag into the file it stopped working.

"Wut." is my only response.

Edit 3

I changed my CSS to this, and it works. I haven't gone through my previous CSS file to figure out why it doesn't work with it, just thought I would update everyone. I posted 2 JS fiddle links, one with my base CSS (please remember this was a work in progress, and that I am partially colorblind so the bright colors help me see the differences), and the other with the CSS below, which runs fine.

In summary: Today I learned that CSS can keep javascript events from firing.

html, body, body>div{
                height:100%;
            }

            body > div{
                width:900px;
                text-align:left;
                margin:0 auto 0 auto;
                background-color:white;

            }

            body{
                text-align:center;
                background-color:grey;
                padding:0;
            }

            #wrapper{

                position:relative;
                width:inherit;
                height:inherit;
            }

            #footer{
                position:absolute;
                bottom:0px;
                text-align:center;
                width:inherit;
            }
13
  • Try putting your <script> tags before the closing </body> tag Commented Apr 17, 2014 at 2:11
  • @AkinkunleAllen while that's a good suggestion for performance reasons, the OP is wrapping the code in a domready block, so the code will be executed when the page's DOM elements are ready.
    – csuwldcat
    Commented Apr 17, 2014 at 2:16
  • See my edit; events are still not firing. If I call the $('employee').morph property, it works correctly. Doesn't do me a lot of good, but it lets me know that it's not the morph framework. Are the event handlers standard in the core mootools, if anyone can answer that off top.
    – Jhecht
    Commented Apr 17, 2014 at 2:26
  • 1
    Okay so going through line-by-line, I deleted the declaration for my CSS file <link rel=...., and that appears to have it working. and I cannot figure out why.
    – Jhecht
    Commented Apr 17, 2014 at 5:29
  • 1
    the problem is your domready. mootools.net/docs/core/Utilities/DOMReady - add it to window, not document (as @csuwldcat pointed out) Commented Apr 17, 2014 at 8:26

2 Answers 2

1

I think you have a syntax error in background: color

this.morph({
    opacity: 0.5,
    backgroundColor: color // is color defined?
});
3
  • color was defined as red, not sure how i forgot to copy that over, but it was directly above the $('employee') line
    – Jhecht
    Commented Apr 17, 2014 at 2:23
  • Make sure mootools is included correctly (e.g. correct path). Your code works in this example jsfiddle.net/HD8Er/1
    – NoGray
    Commented Apr 17, 2014 at 2:37
  • It's there, the console.log(MooTools.version) displays as normal. And it's weird, it works via that JSFiddle for me as well, just not on my machine right here.
    – Jhecht
    Commented Apr 17, 2014 at 2:46
1

The MooTools domready event is only available on the window object - here's your example in working order: http://jsbin.com/rucaz/1/edit

For reference: http://mootools.net/docs/core/Utilities/DOMReady

5
  • @Jhecht I'm not sure why your version doesn't work, here's your exact example with domready added to the window object - it works as expected: jsbin.com/rucaz/1/edit
    – csuwldcat
    Commented Apr 17, 2014 at 3:47
  • I'm not sure either. Code works there, not on my machine. that is the only difference, but it shouldn't affect anything.
    – Jhecht
    Commented Apr 17, 2014 at 5:23
  • what have you got in that style? any expressions/behaviours/data:uri / @import bits? also, what have you got for #employee selector and via inherited, particularly to do with background/background-color? chances are the Fx CSS parser was unable to retrieve and parse it correctly to set the from value before it can arrive to the new value. things like rgba() will fail. Commented Apr 17, 2014 at 20:04
  • you want to add a breakpoint on this line in mootools-core: github.com/mootools/mootools-core/blob/master/Source/Fx/… - and see the value of parsed, please. if possible post findings along with computed CSS in case there is an actual bug (doubtful, limitations are well known) Commented Apr 17, 2014 at 20:10
  • ALSO. color cannot be red - needs to be a valid rgb / hex string. Fx.Morph happens by breaking down from and to values and setting middle value points around your Fx.Transitions path and fps settings. it can't do that if the values are not of the same type. this should work independently of your CSS: jsbin.com/kuzojava/1/edit Commented Apr 17, 2014 at 20:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.