Skip to main content
Inspiring
Feb 13, 2020 3:10 AM UTC
Question

Unable to Retrieve Object's Position Using JavaScript

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

Inspiring
Feb 13, 2020 11:10 AM UTC

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.

 

Translate
Inspiring
Feb 13, 2020 7:19 PM UTC

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%;​">​
Translate
Lilybiri
Legend
Feb 13, 2020 7:22 PM UTC

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

Translate