Skip to main content
Inspiring
January 25, 2017
Answered

Absolute positioning of objects with JavaScript

  • January 25, 2017
  • 2 replies
  • 2314 views

Hi,

I`m using Captivate 9 and publish in HTML5.

If I have a classical project (non-responsive) with a specific size, say 1200 x 800 pixels, is there a way to place an object to some specific absolute x-y-position on the screen using JavaScript? For example if I like to place a SmartShape at x=100 and y=200? (Here, x and y could probably depend on a variable).

I know how to place an object relative to its previous position using JS, seeCaptivate scripting - change x & y position of object

Of course I could use this to calculate the respective absolute position, but sometimes it`s easier just to enter the coordinates. This should be possible with JS without using any widget.

Any help is greatly appreciated!

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    var myObj = document.getElementById("objectName");

    myObj.style.left = varX+"px";

    myObj.style.top = varY+"px"

    2 replies

    Lilybiri
    Legend
    January 25, 2017

    I am a bit lazy concerning JS. In this case I would use the CpExtra widget by InfoSemantics. It has two variables xcmndPosX and xcmndPosY that can be used for what you are asking here. Much easier, less headaches. Have a look:

    http://www.infosemantics.com.au/adobe-captivate-widgets/cpextra/help/command-variables/positioning-slide-objects

    Inspiring
    January 25, 2017

    Hi Lilybiri,

    my projects had some problems with Edge when I used CpExtra (I think they even say that CpExtra had not been extensively tested with Edge). I want to avoid a widget here as I think positioning of objects should be a standard application for JS.

    Lilybiri
    Legend
    January 25, 2017

    True, was one of the testers, and Edge was still pretty new.

    It should be possible with JS, but cannot help more.

    Justenuf2bdangerous
    Inspiring
    January 25, 2017

    I'm unclear on what you want here - are you looking to lock an object into place in a master slide layout?  The x and y coordinates for any static object on a screen can entered in the properties tab:

    Capture

    Is there something I'm missing in what you want the object to be able to do with regard to the variables  you mentioned?

    Inspiring
    January 25, 2017

    Thank you for the answer! But what I need is to position an object with JavaScript. The position of objects (in my projects) often depend on some other variables.

    Say I have two variables var_1 and var_2 (maybe depending on text entry by the user or on other things). Now I want to set the object (SmartShape or whatever) on  X = var_1 and Y = 3*var_2 (just as an example).

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    January 26, 2017

    var myObj = document.getElementById("objectName");

    myObj.style.left = varX+"px";

    myObj.style.top = varY+"px"