Forum Discussion
Anyone find a fix for JavaScript Text Color Change?
- 3 months ago
Found it, and here it is...
https://360.articulate.com/review/content/b95f42f6-332c-4045-a261-01acd91fc3e9/review
Im actually quite sure there will be situations where this will not work. Eg. text on a button is different...and there are quite some ways to use text in Storyline. I might walk through all text-options and fix this so you can use it on any text in any circumstance. But for now, for your case this sure will suffice.
I added a function in it i use for creating randomcolors.const parent = document.querySelector('[data-acc-text="text2Change"]'); gsap.to(parent, {duration:0.7,scale:1.5,transformOrigin:"top left"}); Array.from(parent.children).forEach((child, index) => { const txtSpan = child.querySelectorAll('tspan'); for (let i = 0; i < txtSpan.length ; i++) { txtSpan[i].style.fill = generateRandomColor(); } }); function generateRandomColor(){ let maxVal = 0xFFFFFF; // 16777215 let randomNumber = Math.random() * maxVal; randomNumber = Math.floor(randomNumber); randomNumber = randomNumber.toString(16); let randColor = randomNumber.padStart(6, 0); return `#${randColor.toUpperCase()}` }
And offcourse the source file :-)
Found it, and here it is...
https://360.articulate.com/review/content/b95f42f6-332c-4045-a261-01acd91fc3e9/review
Im actually quite sure there will be situations where this will not work. Eg. text on a button is different...and there are quite some ways to use text in Storyline. I might walk through all text-options and fix this so you can use it on any text in any circumstance. But for now, for your case this sure will suffice.
I added a function in it i use for creating randomcolors.
const parent = document.querySelector('[data-acc-text="text2Change"]');
gsap.to(parent, {duration:0.7,scale:1.5,transformOrigin:"top left"});
Array.from(parent.children).forEach((child, index) => {
const txtSpan = child.querySelectorAll('tspan');
for (let i = 0; i < txtSpan.length ; i++) {
txtSpan[i].style.fill = generateRandomColor();
}
});
function generateRandomColor(){
let maxVal = 0xFFFFFF; // 16777215
let randomNumber = Math.random() * maxVal;
randomNumber = Math.floor(randomNumber);
randomNumber = randomNumber.toString(16);
let randColor = randomNumber.padStart(6, 0);
return `#${randColor.toUpperCase()}`
}
And offcourse the source file :-)
This is great, thank you. I will give it a try shortly when I can return to the project. The buttons are not so much a problem because those I can bounce off the states, I only need this to affect my text box placeholders.
I essentially have it working as
When User Clicks "Theme Button"
Toggle DarkMode (variable)
When Variable Changes, if DarkMode = True, Execute JavaScript (This affects the Settings menu, blocks/tiles and Placeholder text objects in the Master Slide)
When Variable Changes, Toggle DarkMode = True, Change State of "X" to Dark (This affects things like our company logo, background tint, and buttons)