Problem: Hi, I want to identify all objects on a given slide that have an opacity that is not zero. Can this be done through JS? I know I can set opacity through JS but I fail to get the opacity of an element through JS. I tried
hmmm, looks like that is not the problem. It works in the other project once I have zoomed the circle in and out. But if I have a circle and want to get its opacity, it’s an empty string. Once I set opacity through JS I then get the opacity.
In theory, I could set opacity on load of slides, but that seems kind of messy.
I see… you need opacity right away on load prior to any interaction?
Is the value itself important or do you just need to know which ones are visible? So zero or one?
I was wondering if there was something we could do with adding a show/hide when you fade out, then hide and show then fade in. Perhaps then you could make use of another tactic.
prez.object("Circle").visible();
This would give you a true or false result but at least you might be able to work with that.
Not sure if that would be a working approach for you or not - just trying to brainstorm a bit.
This is set using the CSS filter property, so you can’t get it from the opacity property.
Please try using the following script instead, it should work better:
getFilterOpacity(prez.object('Shape_3').node);
// return value from 0 to 1
function getFilterOpacity(el) {
var filter = getComputedStyle(el).filter;
var match = filter.match(/opacity\(([^)]+)\)/);
if (!match) return 1; // no filter opacity applied
var value = match[1];
if (value.includes('%')) {
return parseFloat(value) / 100;
}
return parseFloat(value);
}