Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:56:03+00:00 2026-05-31T03:56:03+00:00

I have this basic script that makes an element show onmouseenter, and hide onmouseleave.

  • 0

I have this basic script that makes an element show onmouseenter, and hide onmouseleave.
In HTML version works fine, but i need to display it in wordpress; but in WP didn’t work.

Firebug shows the following error:

sidebar_animate is not defined

How can I fix this?

The script

<script language="javascript">

    function sidebar_animate(px) {
       $('#sidebar').animate({
       'marginLeft' : px
     });
}
</script>

Body

<div id="sidebar" onmouseenter="sidebar_animate('+180px');" 
  onmouseleave="sidebar_animate('-20px');"
  style="background-color: red; width: 240px; height: 100px; position: absolute; left: -180px;" >
  This is going to move
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:56:05+00:00Added an answer on May 31, 2026 at 3:56 am

    How about binding the event handlers with jQuery so your code is all in one spot:

    <script language="javascript">
    
    //wait for document.ready to fire so elements are available to manipulate
    $(function () {
    
        //setup object to convert the type of event fired to the pixel offset to apply for the event
        var eventToPx = {
            mouseenter : 180,
            mouseleave : -20
        };
    
    
        //bind an event handler to the `#sidebar` element for `mouseleave` and `mouseenter`
        $('#sidebar').on('mouseenter mouseleave', function (event) {
    
            //animate this element's `margin-left` property to the specified number of pixels
            //note that jQuery assumes pixels if you omit units
            $(this).stop().animate({
                marginLeft : eventToPx[event.type]
            }, 500);
        });
    });
    </script>
    

    Here is a demo: http://jsfiddle.net/jasper/mYwqE/

    Notice that I added .stop() to your code just before the .animate() call. It will stop the current animation if a new one is queued, so the animations won’t queue-up if the user mouse-over’s and mouse-out’s the element many times rapidly.

    Note that .on() is new as of jQuery 1.7 and in this case is the same as using .bind(): http://api.jquery.com/on

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a basic html/css question... I have a simple one-button form that
I have a basic website nav layout that looks like this: <li class=folder parent_folder>
I have created a basic WCF service in IIS. I am aware that this
I have a basic HTML file, using jQuery's ajax, that is connecting to my
I have a python script that works great when run by itself. Based on
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
I realize this is a basic question but I have searched online, been to
So this seems pretty basic but I can't get it to work. I have
I'm a noob so this is probably basic stuff, but I have tried to
I have some basic idea on how to do this task, but I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.