/ / Come trascinare un bambino in base alla posizione del mouse in Jquery? - javascript, jquery, html, css, jquery-ui

Come trascinare un bambino in base alla posizione del mouse in Jquery? - javascript, jquery, html, css, jquery-ui

Ho una grande mappa trascinabile per vedere tutti i luoghi sulla mappa. Ma voglio essere in grado di trascinarlo in base alla posizione del mouse.

Come trascinare un bambino in base alla posizione del mouse in Jquery?

Ecco il mio codice di trascinamento:

$(".map").draggable({
containment:[(parseInt($(".hk").width()) - parseInt($(".hkc").width())) * -1,
(parseInt($(".hk").height()) - parseInt($(".hkc").height())) * -1, 0, 0],
cursor: "move"
})

La mia demo è Qui

e qui è lo screenshot:

inserisci la descrizione dell'immagine qui

inserisci la descrizione dell'immagine qui

inserisci la descrizione dell'immagine qui

risposte:

0 per risposta № 1
    // Variables for current position
var x, y;

function handleMouse(e) {
// Verify that x and y already have some value
if (x && y) {
// Scroll window by difference between current and previous positions
window.scrollBy(e.clientX - x, e.clientY - y);
}

// Store current position
x = e.clientX;
y = e.clientY;
}

// Assign handleMouse to mouse movement events
document.onmousemove = handleMouse;