I searched this over internet for over 3 hours and none of the suggestions work in my code. What i am trying to do is to slide pictures to left one by one in each click (total 3 pictures) and when the last picture is in the screen stop sliding left and slide back to the first picture. To do that I need to detect the left margin of the first picture when it hits a certain spot (180em to the left) and compare it to an "ems" value (code is below). The "if" statement never shoots, it always directs to "else".
I tried to get the left border position (or margin) of the first picture with "$('#picture1').offsetLeft", "$('#picture1').layerX", "$('#picture1').left" too but none of them worked.
If you can direct me to another website, another question in Stackoverflow or give me a solution I will appreciate it.
Note: I am very very new with javascript, if there are mistakes in my code or my question correct me. Thank you.
var position = parseInt(jQuery("#picture1").css("margin-left"));
var left_border = '180ems';
$(function() {
$(".button").click(function() {
if (position > 180ems) {
$("#picture1").animate({
left: '-=60em'
}, 600);
$("#picture2").animate({
left: '-=60em'
}, 600);
$("#picture3").animate({
left: '-=60em'
}, 600);
}
else {
$("#picture1").animate({
left: '+=180em'
}, 600);
$("picture2").animate({
left: '+=120em'
}, 600);
$("#picture3").animate({
left: '+=60em'
}, 600);
};
});