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 3982580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:32:40+00:00 2026-05-20T05:32:40+00:00

What I’m trying to do here is to show a loading box that follows

  • 0

What I’m trying to do here is to show a loading box that follows cursor after submitting a form using MooTools. However, I’ve simplified the problem into just 1 div and 1 form.

script:

document.addEvent('domready', function(){

    $('test_form').addEvent('submit', function(){
        var box = $('box');

        document.addEvent('mousemove', function(e){
            box.setStyles({
                top: e.page.y,
                left: e.page.x
            });
        });


        box.setStyle('display', 'block');

        return false;
    });
});

html:

<div id="box">
</div>

<form id="test_form" action="">
    <label>Name: </label><input type="text" name="name" /><br/>
    <input type="submit" value="Submit" />
</form>

css:

#box {
    width: 50px;
    height: 50px;
    background-color: blue;
    position: absolute;
    display: none;
}

#test_form {
    margin-left: 150px;
}

When the form is submitted, it will show the hidden blue div and it will follow the cursor. However, I can’t make the div appear at mouse position when the form is submitted. The ‘mousemove’ will not fire until we move the mouse; thus, the blue div appears at position (0,0) immediately after showing. Is there a way to get the mouse position right after the form is submitted? Or is there an alternative way to do it?

Any suggestions is greatly appreciated!

Updated:

I don’t want to add mouse event (mousemove) before the form is submitted. The reason is simply because I don’t want the javascript to keep on checking the mouse position when it’s not necessary. Just try to avoid performance issue!

  • 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-20T05:32:41+00:00Added an answer on May 20, 2026 at 5:32 am

    basically, the submit is an event but its event.type is submit and it won’t contain mouse info.

    your bet is to re-arrange your javascript so it moves the box quietly all the time and just shows the box by changing display when submitted. something like that:

    http://jsfiddle.net/jtLwj/

    (function() {
        var box = $('box');
    
        document.addEvent('mousemove', function(e) {
            box.setStyles({
                top: e.page.y,
                left: e.page.x
            });
        });
    
        $('test_form').addEvent('submit', function(ev) {
            ev.stop();
            box.setStyle('display', 'block');
            var sizes = box.getPosition();
            box.set("html", [sizes.x, ' x ', sizes.y].join("<br/>"));
        });
    })();
    

    reading the box position after submit will return your cursor 🙂

    downside: latency of changing css for the invis box before submit.

    edit better version w/o the change to dom all the time:

    (function() {
        var lastEventObject, eventListener = function(e) {
            // keep a scoped referene of the last known mouse event object
            lastEventObject = e;
        };
    
        document.addEvent('mousemove', eventListener);
    
        document.id('test_form').addEvent('submit', function(e) {
            e.stop();
            // not needed anymore...
            document.removeEvent("mousemove", eventListener);
    
            // show the box at last known mouse loc
            document.id("box").setStyles({
                display: 'block',
                left: lastEventObject.page.x,
                top: lastEventObject.page.y
            });
    
            // attach to mousemove or whatever....
    
        });
    })();
    

    this is as good as it will get, I’m afraid. the footprint of the reference to the event object is minimal at best.

    fiddle: http://jsfiddle.net/dimitar/jtLwj/1/

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.