Does anyone know if there is away to dynamically change the size of a shape using variables without using states? Example: a rectangle used as a sliding scale based on how someone answers questions during a course.
Hi all, If someone is still looking for a solution. You can do it with a picture (it's easier to get the element with the filename of the picture) and JavaScript. Below is the JavaScript code for rotation and you can see the code for scale in the attached file.
var elem = null; var slide = parent.document.getElementById('slide'); var divs = slide.querySelectorAll('div');
for (var i in divs) { if (divs[i].tagName == "DIV") { // data-acc-text attribute contains the filename var attr = divs[i].getAttribute('data-acc-text'); // eg. avatar.png is the filename of the picture if (attr && attr=='avatar.png') { elem = divs[i]; break; } } }
if (elem) { var style = window.getComputedStyle(elem); var matrix = style.transform.match(/matrix.*\((.+)\)/)[1]; var values = matrix.split(', '); // scale value var s = Math.sqrt(values[0]*values[0] + values[1]*values[1]); var player = GetPlayer(); // angle from the slider var r = player.GetVar('rotationValue') ; elem.style.transform = "translate("+values[4]+"px, "+values[5]+"px) rotate("+r+"deg) scale("+s+")"; }
Thanks for the demo file, I'd love to adjust it for a project I'm working on. I've tried copying and pasting the .png and the sliders into a new .story file so that I can play with them but it doesn't work when I publish it. The variables and triggers have copied across. Just wondering what it is I've missed.
Just changed Gaston's version to use GSAP as that is build into Storyline360. Gives many more possibilities too... like easing and more.
This was the original code... var elem = null; var slide = parent.document.getElementById('slide'); var divs = slide.querySelectorAll('div');
for (var i in divs) { if (divs[i].tagName == "DIV") { var attr = divs[i].getAttribute('data-acc-text'); if (attr && attr=='avatar.png') { elem = divs[i]; break; } } }
if (elem) { var style = window.getComputedStyle(elem); var matrix = style.transform.match(/matrix.*\((.+)\)/)[1]; var values = matrix.split(', '); var r = Math.round(Math.asin(values[1]) * (180/Math.PI)); var player = GetPlayer(); var s = player.GetVar('scaleValue') ; elem.style.transform = "translate("+values[4]+"px, "+values[5]+"px) rotate("+r+"deg) scale("+s+")"; }
And this is the same but then using GSAP. As you can see...shorter and simpler.
//this needs to be the 'acc-name' of the image let imageToChange = document.querySelector("[data-acc-text='avatar.png']");
let player = GetPlayer(); let s = player.GetVar('scaleValue'); gsap.to(imageToChange, { duration:0.1,scale: s });
13 Replies
Sorry Magda, this is not currently possible in Storyline.
Thanks. I will hack together a workaround. These are the times I miss Flash:)
Hi, Magda -- To the best of my knowledge, using states would be the way to go, but you are definitely welcome to submit a feature request.
Cannot dynamically do much with it at all?
Flash is so much more advanced than this powerpoint macro program. Going backwards with HTML5.
Hi all, If someone is still looking for a solution. You can do it with a picture (it's easier to get the element with the filename of the picture) and JavaScript. Below is the JavaScript code for rotation and you can see the code for scale in the attached file.
As a shape is SVG Gsap will work. Check my posts on Gsap.
@Math, Thank you for your reply.
Hi Gaston
Thanks for the demo file, I'd love to adjust it for a project I'm working on. I've tried copying and pasting the .png and the sliders into a new .story file so that I can play with them but it doesn't work when I publish it. The variables and triggers have copied across. Just wondering what it is I've missed.
Just changed Gaston's version to use GSAP as that is build into Storyline360. Gives many more possibilities too... like easing and more.
This was the original code...
var elem = null;
var slide = parent.document.getElementById('slide');
var divs = slide.querySelectorAll('div');
for (var i in divs) {
if (divs[i].tagName == "DIV") {
var attr = divs[i].getAttribute('data-acc-text');
if (attr && attr=='avatar.png') {
elem = divs[i];
break;
}
}
}
if (elem) {
var style = window.getComputedStyle(elem);
var matrix = style.transform.match(/matrix.*\((.+)\)/)[1];
var values = matrix.split(', ');
var r = Math.round(Math.asin(values[1]) * (180/Math.PI));
var player = GetPlayer();
var s = player.GetVar('scaleValue') ;
elem.style.transform = "translate("+values[4]+"px, "+values[5]+"px) rotate("+r+"deg) scale("+s+")";
}
And this is the same but then using GSAP.
As you can see...shorter and simpler.
//this needs to be the 'acc-name' of the image
let imageToChange = document.querySelector("[data-acc-text='avatar.png']");
let player = GetPlayer();
let s = player.GetVar('scaleValue');
gsap.to(imageToChange, { duration:0.1,scale: s });
Added the adapted version.
And as the original question of this post was about shapes...
https://360.articulate.com/review/content/be8724c6-9fcd-42de-854f-554042ded54f/review
I added a shape scale and rotation to it. Toggling the checkboxes x and y you can scale it accordingly.
PS. this was already possible in Storyline 1, allthough getting Javascript to work was way more complex.
Hi Emma,
Could you please share your .story file so I can see what you missed? (Just a .story file including the slide in question)
Good job Math! Your version is indeed shorter.
You can even set duration to 0 instead of 0.1 cause you don't need any animation.
True...even better then to use gsap.set
gsap.set(imageToChange,{scale:s});
Used to the syntax... and it makes it easier to add eases or anything else.
GSAP is really magical.
https://greensock.com/
And luckily Articulate is now quite aware of its power...they update it now regularly.
The latest version 3.10.4 is active in Storyline360