Skip to main content
Inspiring
February 6, 2017
Answered

Changing the stack order with JavaScript

  • February 6, 2017
  • 1 reply
  • 2213 views

Hi all,

is there any way (JavaScript or whatever) to change the stack order (= z-order) of objects in a Captivate project?

It would be extremely useful to be able to rearrange the stack order without having to create new objects every time. In general, there are different methods in JavaScript for doing so. Has anybody ever successfully employed them on Captivate?

I use Captivate 9 and publish in HTML5. Thanks in advance for any advice!

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    Assume we have two objects (object1 and object2) where object1 is on the "top layer". At some point we want to have object2 at the top layer. Then we need to create a third element (which is equal to object2) which is in the stack order on top of object1.

    This is not so bad if we have only two objects und both object are Smartshapes, for example. However the situation gets much worse

    - if the objects are not Smartshapes but web objects. Each object has to be loaded separately which can consume a lot of time and memory resources (depending on the kind of web object).

    - if we do not have only two objects but for example ten objects which can be arranged in different z-orders. There are 10! = 10*9*8*...*2*1 = 3.628.800 different possible orders. Maybe the order shall depend on some variable - this would never be possible if you have to create each order separately with different objects.


    You can do it if you get the correct element. For example, to move Text_Caption_2 above Text_Caption_1 you need to get the rewrap element of Text_Caption_2:

    document.getElementById("re-Text_Caption_2c").style.zIndex=2000;

    Finding the correct element may be an issue, for Text_Caption_2 there are 3:

    document.getElementById("Text_Caption_2c").style.zIndex=2000;

    document.getElementById("Text_Caption_2").style.zIndex=2000;

    document.getElementById("re-Text_Caption_2c").style.zIndex=2000;

    Only one of them will actually change the zIndiex.

    1 reply

    TLCMediaDesign
    Inspiring
    February 6, 2017

    I'm fairly certain that it's not possible.

    The zIndex is in the CPM.js, you would need to change the zIndex before thee element is rendered in the DOM. You can change it but the page would need to be refreshed.

    Inspiring
    February 7, 2017

    Ok, thank you for the answer. That´s a pity. This would be a really useful tool.

    So if somebody has a great idea how it could be done - please let me know!

    RodWard
    Community Expert
    Community Expert
    February 7, 2017

    Michael,

    What would be the benefit of rearranging the stack order INSTEAD of using different objects?

    I'm not sure I understand your use case.