Is there a way to control the level of implementation of a class change in JS / jQuery.
Imagine the following:
.box {
background: green;
width: 500px;
height: 100px;
transition:all 1s;
}
.box.active {
tranform: translateX(200px);
width:250px;
background:blue;
}
Conventionally using jQuery for example we would add and remove the new class experiencing an animation as it changes to the "active" state.
$("box").addClass("active");
BUT.. What is we want to implement 50% or even 28% of the active state. Imagine a scrolling gallery where we have multiple elements experiencing multiple transitions and we are matching the extent of those transitions to the level the user has scrolled or dragged on the gallery. Hope that makes sense.
eg. $("box").partialAddClass("active", 20% );
Is such a thing possible. Are there alternative ways of achieving this. We can obviously do this to some extent by creating the css properties of the normal and active state in JS and applying them but this works for numeric qualities like opacity
and width
. It is hardly the most efficient method for the programmer though. Is there an easy option.