Archive for June, 2017

move a div

June 28, 2017

with position

xpos = xpos + x;
ypos = ypos + y;

$(".inner").parent().css({ position: 'relative' });
$(".inner").css({ left: xpos + 'px', top: ypos + 'px', position: 'absolute' });

console.log('AFTER x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);

with offset

console.log('BEFORE x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);

xpos = xpos + x;
ypos = ypos + y;

$(".inner:last").offset({top: ypos,left: xpos});
console.log('AFTER x:' + $('.inner').position().left + ' y:' + $('.inner').position().top);