[英]jQuery How to check if the current position of a div is equal to
I am stuck. 我被卡住了。 I am working on a jQuery game and I need to know the current position of a object and check if it equals to 0. I tried different things but none of them worked.
我正在研究一个jQuery游戏,我需要知道一个对象的当前位置,并检查它是否等于0.我尝试了不同的东西,但没有一个工作。 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);
});
}
just change your code to this 只需将您的代码更改为此
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);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.