Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
tenho o seguinte código que que pega as cordenadas da pagina mais nao consigo de geito nenhum gravar essas cordenadas em uma variavel js para usa-la depois.
<html>
<script language="Javascript1.2">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempy = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempy = event.clientY + document.body.scrollTop;
}
else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
document.getElementById("vx").innerHTML = tempX;
document.getElementById("vy").innerHTML = tempY;
return true;
}
</script>
<BODY>
<div id="x">X <span id="vx"></span></div><br>
<div id="y">Y <span id="vy"></span></div>
</body>
</html>
SE EU COLOCAR EM UMA FUNÇAO NAO FUNCIONA
EXEMPLO:
$(document).ready(function() {
$("#animado").animate({left: tempX, top: tempY}, 1500);
});
alguem sabe porque nao funciona?
nao funcionou:
veja o código que nao funcionou:
<HTML>
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<body>
<div id="animado">
<h3>Este é uma DIV animada!!</h3>
</div>
</body>
<heady>
<style type="text/css">
body {
background: #eee;
}
#animado {
background: #008;
position: absolute;
width: 200px;
height: 200px;
border: 1px solid #00f;
}
#animado h3 {
font-family: Verdana;
}
</style>
<script type="text/javascript">
$(document).ready(function {
$(document).mousemove(function(event) {
$("#animado").animate({left: event.pageX, top: event.pageY}, 1500);
});
});
</script>
<BODY>
</heady>
</body>
</HTML>
deve ser algum erro bobo mais nao acho onde.
Você pode usar a função do jQuery mousemove. Assim ó:
$(document).ready(function {