Skip to main content
Inspiring
February 13, 2020
Question

Unable to Retrieve Object's Position Using JavaScript

  • February 13, 2020
  • 1 reply
  • 719 views

I want to be able to change an object's position using JavaScript. I thought I found the answer here:

https://community.adobe.com/t5/captivate/captivate-scripting-change-x-y-position-of-object/td-p/8606684?page=1 

When I tried it, I got a blank. I'm not sure what the reason is.

var obj = document.getElementById( 'Image_12c' );
var posX = parseInt( obj.style.left );

alert(posX);
This topic has been closed for replies.

1 reply

Inspiring
February 13, 2020

I think it's just because posX has the value 0 at this stage. Try console.log intead of alert and check in the browser's console. 

If you fired obj.style.left = ( posX + 10 ) + 'px'; at it now like advised in the post you cited, your image should jump 10 pixels over to the right as expected.

If you run this script on slide enter, you might have to wrap it in a timeout to give the image time to load.

 

Inspiring
February 13, 2020

When I check console.log, it says NaN.

 

When I use this:

var obj = document.getElementById( 'Image_12c' );
console.log(obj);

 

I get this:

(unknown) 
<canvas id=​"Image_12c" class=​"cp-shape" width=​"196" height=​"156" style=​"left:​ 0px;​ top:​ 0px;​ right:​ 0px;​ bottom:​ 0px;​ width:​ 100%;​ height:​ 100%;​">​
Lilybiri
Legend
February 13, 2020

Will not help with JS, but are yuu busy with a responsive project (Fluid Boxes)?