Jump to content

Jquery: Drag and Drop


ruimcosta
 Share

Recommended Posts

Biba,

A questão do drag and drop é pacífica. A ajuda que preciso é a seguinte:

- Ter uma div que simule uma folha A4;

- Ao arrastar um quadrado, conseguir obter as coordenadas x,y dentro dessa div para de seguida obter a distancia TOP e LEFT desse quadrado em relação à A4?

Alguma ideia para isto?

Abraços e beijinhos,Rui Costa

Link to comment
Share on other sites

Penso que procuras algo deste genero

function doSomething(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) 	{
	posx = e.pageX;
	posy = e.pageY;
}
else if (e.clientX || e.clientY) 	{
	posx = e.clientX + document.body.scrollLeft
		+ document.documentElement.scrollLeft;
	posy = e.clientY + document.body.scrollTop
		+ document.documentElement.scrollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}

Ve melhor aqui:

http://www.quirksmode.org/js/events_properties.html

Ou da uma vista de olhos por aqui

http://docs.jquery.com/Tutorials:Mouse_Position

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.