JQuery How to check if current div position is equal to
I am stuck. I am working on a jQuery game and I need to know the current position of an object and check if it is 0. I tried different things but none of them worked. Here is the code:
function movePoint() {
$( '.point' ).each( function() {
if($(this).attr('id').position().left == 0) {
console.log("Yay!");
}
$( this ).css( 'left', $( this ).position().left - ( speed + (roundsClicked / 10) ) );
console.log("Left position of your element - " + $(this).position().left);
});
}
+3
source to share
1 answer
just change your code to
function movePoint() {
$( '.point' ).each( function() {
if($(this).position().left == 0) {// if($(this).css('left') == '0px')
console.log("Yay!");
}
$( this ).css( 'left', $( this ).position().left - ( speed + (roundsClicked / 10) ) );
console.log("Left position of your element - " + $(this).position().left);
});
}
+1
source to share