Reputation: 4492
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?
Upvotes: 0
Views: 854
Reputation: 14873
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);
});
Upvotes: 0
Reputation: 14967
<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>
Upvotes: 1