Discussion in ' JavaScript ' started by ImozebApr 28, Log in or Sign up. Social Buttons. Digital Point.

How do I position a div based on the mouse position? I've searched some sites and I have come up with this.

Subscribe to RSS

Javascript Code: document. ImozebApr 28, I'm trying to get the current scroll for x and y but it isn't working. Any ideas? ImozebApr 30, So then why is it not working with scrolling?

ImozebMay 2, ImozebMay 3, We can't just assign it to a global variable, probably because the way it behaves: it is created when needed, propagates through elements, and done. Other elements might use it later then with different event structure.

Last edited: May 4, Could you give me an example, please? ImozebMay 4, It says clientX is not a variable. ImozebMay 6, Last edited: May 6, ImozebMay 7, I can be finally be famous now. Last edited: May 7, You must log in or sign up to reply here.

Background Image Move on Mousemove - Javascript Mousemove Animation Effects

Show Ignored Content. Your name or email address: Do you already have an account? No, create an account now. Yes, my password is: Forgot your password?Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience.

I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect. Adding interactive animations can give a fresh look to any website!

Many websites use a background image to cover the complete visible screen.

jquery move image based on mouse position

Today we'll see how to add an interesting effect on the background image: to move the background image with the mouse cursor movement using CSS and jQuery.

Define an empty div element with an ID attribute. Here is the complete jQuery code:. Our jQuery solution makes use of the mousemove event on the background wrapper element to calculate the new top and left position for background image and set its background position accordingly. You can modify the jQuery code as per your requirements to increase or decrease the degree of pixel movement.

Have fun! Newer Post Older Post Home.We can find the X and Y coordinates using jQuery pageX and pageY events to locate the mouse position on the image or any element to be precise. We can get the location of the mouse either by hovering it over the image or by clicking the image.

We will add a Sprite image in our web page, which has three small images embedded together in a single image file. We will also add a DIV element, which will show us the coordinates when we move, hover or click on the image. To get the precise X, Y coordinates of the image we will use jQuery offset method to remove spaces between the window and image container. The DIV is acting as a container to the image. This way even if we add a little padding to the container, the coordinates of the image is precise.

We have seen how x, y coordinates can be located in an image inside another image, in fact these properties are not confined to images only, you can try with other HTML elements like DIV or P.

Sprite images are a collection of multiple image bundled together in a single image. Please enable JavaScript to view this page properly. Images play a very important role while designing a website. Sometimes we add a wide range of images on a single web page. We embed multiple images in a single image to save load time of the web page. Finding the precise X and Y coordinates of an image in the stack using mouse click or mouse Move, eliminates guesswork.

Like this Article? Subscribe now, and get all the latest articles and tips, right in your inbox. Delivered by FeedBurner.When the positioned element overflows the window in some direction, move it to an alternative position.

Move background image based on mouse position from right side of screen

The second provides feedback about the position and dimensions of both elements, as well as calculations to their relative position. Both target and element have these properties: elementlefttopwidthheight. The jQuery UI. This plugin extends jQuery's built-in. If jQuery UI is not loaded, calling the. However, the expected behavior will not occur. Defines which position on the element being positioned to align with the target element: "horizontal vertical" alignment.

A single value such as "right" will be normalized to "right center""top" will be normalized to "center top" following CSS convention. Acceptable horizontal values: "left""center""right". Acceptable vertical values: "top""center""bottom". Example: "left top" or "center center". Each dimension can also contain offsets, in pixels or percent, e. Percentage offsets are relative to the element being positioned. Defines which position on the target element to align the positioned element against: "horizontal vertical" alignment.

See the my option for full details on possible values. Percentage offsets are relative to the target element. Type: Selector or Element or jQuery or Event. Which element to position against. If you provide a selector or jQuery object, the first matching element will be used.

If you provide an event object, the pageX and pageY properties will be used. Example: " top-menu". Whichever side allows more of the element to be visible will be used. Then the fit logic is applied to ensure as much of the element is visible as possible. When specified, the actual property setting is delegated to this callback. Receives two parameters: The first is a hash of top and left values for the position that should be set and can be forwarded to.

Type: Selector or Element or jQuery. Element to position within, affecting collision detection. Note: jQuery UI does not support positioning hidden elements. This is a standalone jQuery plugin and has no dependencies on other jQuery UI components.

jquery move image based on mouse position

A simple jQuery UI Position example.There are situations sometimes when it is required that an image should be draggable within the container div. Something like the demo below is required :.

Dragging can be achieved by combining mousedownmousemove and mouseup events. While dragging we are changing the top and left properties of the image. When the top and left properties of the image are changed, the part of the image seen in the container will change as well. For example below, the first image has top and left property set to 0 and 0.

The second image has top and left set to px and px. The third one has top and left as px and px. When the image is dragged we can change the top and left properties depending on the amount of the drag. For example if we drag the image 50px upwards and 50px to the left, we should reduce the top value by 50px and left value by 50px to see the new part of the image.

Dragging is a combination of 3 mouse events. When the user starts dragging he presses the mouse down mousedown event. Then he moves the mouse mousemove events. To stop dragging he releases the mouse mouseup event. Firstly check whether the image has been loaded or not.

Otherwise on the first page load, jQuery will return the height and width of the image as 0. There can also can be a chance that the image is already loaded and available in the browser cache. When the user performs a mousedown event we initialize a global variable and set it to 1.

This is important because the user may move the mouse without keeping the mouse pressed. Dragging occurs only when the mouse is moved keeping the mouse pressed. On each occurring mousemove event we find the position of the mouse in the document through the pageX and pageY properties of the event object. We then find the position of the mouse within the container mouse position in the document - position of the container in the document.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Mouse Position in ASP.NET using JQuery

I am trying to develop a HTML5 white board. I want the users viewing the board to know where exactly the presenter is pointing within the screen. I am able to collect the mouse movements using this jquery function.

jquery move image based on mouse position

But even if i succeed to pass this values to other clients using php, how can I emulate it? Is it possible to move a small pointer image, based on the co-ordinates obtained from the presenter?

This is not very hardware intensive at all. As long as you use. This has actually been done with tutorial included with Node. You say you want to use PHP, and you can probably port his node. Here is a library to help with websockets in php. Create an image on the page with the whiteboard on the viewers browser.

Set the image style to position:absolute and from javascript set the top and left properties acording to the position from the presenters mouse. Use setInterval to make a javascript call to the server and obtain the presenters mouse position. At the presenters computer you need to use setInterval as well to save the mouse position on the server. Learn more. Move an image according to the mouse cordinates using jquery Ask Question.

Asked 8 years, 8 months ago. Active 3 years, 8 months ago. Viewed 16k times.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I am trying to develop a HTML5 white board. I want the users viewing the board to know where exactly the presenter is pointing within the screen. I am able to collect the mouse movements using this jquery function. But even if i succeed to pass this values to other clients using php, how can I emulate it?

Is it possible to move a small pointer image, based on the co-ordinates obtained from the presenter? This is not very hardware intensive at all. As long as you use. This has actually been done with tutorial included with Node. You say you want to use PHP, and you can probably port his node. Here is a library to help with websockets in php. Create an image on the page with the whiteboard on the viewers browser. Set the image style to position:absolute and from javascript set the top and left properties acording to the position from the presenters mouse.

Use setInterval to make a javascript call to the server and obtain the presenters mouse position. At the presenters computer you need to use setInterval as well to save the mouse position on the server. Learn more. Move an image according to the mouse cordinates using jquery Ask Question.

Asked 8 years, 9 months ago. Active 3 years, 8 months ago. Viewed 16k times.


Jquery move image based on mouse position

thoughts on “Jquery move image based on mouse position

Leave a Reply

Your email address will not be published. Required fields are marked *