0

I am using wp_enqueue_script to do this. If I try to do something else lets say popup a dialog, it works but the code below does not. Can someone tell me the problem. thanks.

var $j = jQuery.noConflict();
    $j('#mystuff').hide();
    var mouseLastYPos = null;
    $j(document).mousemove(function(e){ 
        if(mouseLastYPos){ 
            if (e.pageY < mouseLastYPos && e.pageY <= 2){

               $j('#mystuff').show();

            }
        }
        mouseLastYPos = e.pageY;
    });​

here is a working demo of this code on a static page. when you move you mouse to the top of the page some text appears. http://jsfiddle.net/bmHbt/

1
  • most likely a css error with your WordPress layout. If you don't post your WordPress code it's going to be hard to help. Commented Apr 27, 2012 at 19:51

1 Answer 1

4

The jQuery library included with WordPress loads in "no conflict" mode. This is to prevent compatibility problems with other javascript libraries that WordPress can load.

In order to use the default jQuery shortcut of $, you can use the following wrapper around your code:

jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
});

That wrapper will cause your code to be executed when the page finishes loading, and the $ will work for calling jQuery. If, for some reason, you want your code to execute immediately (instead of waiting for the DOM ready event), then you can use this wrapper method instead:

(function($) {
    // $() will work as an alias for jQuery() inside of this function
})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.