tags:

views:

42

answers:

2

I have an element that moves on hover up or down. I need to know the position on that block and see in an text

<script type="text/javascript">
var who = $(".back");
var pozitie = who.position();
$("p.pozitie").text("TOP:" + pozitie.top);
</script>

This script gives me only the start position. I need the position all the time. Can someone help?

A: 
<script type="text/javascript">

var actualPosition = function() {
   var who = $(".back"),
      pozitie = who.position();
   $("p.pozitie").text("TOP:" + pozitie.top);
};

// this
setInterval(actualPosition, 1000);
// or this
who_moves_event_function() {
    //...
    actualPosition();
    //...
}
</script>
andres descalzo
AWESOME!!! YOU ARE AN GENIUS! THANK YOU VERY MUCH! I appreciate your help. I can`t vote because I`m new here!
Adyz
@Adyz - Be sure to accept an answer if it resolves your problem via the empty checkmark beside it :)
Nick Craver
A: 

This will give you current position all the time mouse move

$(".back").hover(function(e) {
    // mouse over
    $("p.pozitie").text("TOP:" + e.pageY+ "LEFT:" + e.pageX);
}, function() {
    // mouse out
    $("p.pozitie").text("TOP:" + e.pageY+ "LEFT:" + e.pageX);
});


$(".back").mousemove(function(e) {
    $("p.pozitie").text("TOP:" + e.pageY+ "LEFT:" + e.pageX);
});
JapanPro
Cool function! Maybe I will need-it one day. Thank you very much!
Adyz
isnt this what you are looking, if not explain with detail, may be i can be exact.
JapanPro
I found the answer var actualPosition = function() { var who = $(".back"), pozitie = who.position(); $("p.pozitie").text("TOP:" + pozitie.top);};// thissetInterval(actualPosition, 1000);
Adyz
great , so you wanted position based on time
JapanPro