I would like to be able to read the value of a CSS property in the middle of a transition before it is fully executed. Is that possible? So if during a transition from 0% to 100%, I were to check halfway through, could I see it at 50%?
The transition-property CSS property sets the CSS properties to which a transition effect should be applied.
The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Tip: A transition effect could typically occur when a user hover over an element.
Triggering transitions You can trigger CSS transitions directly with pseudo classes like :hover (activates when the mouse goes over an element), :focus (activates when a user tabs onto an element, or when a user clicks into an input element), or :active (activates when user clicks on the element).
Specifically around properties, like transition properties, that are not inherited by default. Run this demo in my JavaScript Demos project on GitHub. First off, this is not an AngularJS-specific problem (as you might be lead to believe from the post title). This is just a byproduct of CSS behavior.
Is it possible to get the current css property during a transition in JavaScript?
var timer;
function test(e) {
var $this;
$this = $(this);
timer = setInterval(function () {
console.log($this.height());
}, 500);
}
function untest(e) {
clearInterval(timer);
}
$('div').mouseenter(test).mouseleave(untest);
div
{
transition: height 10s;
-moz-transition: height 10s;
-webkit-transition: height 10s;
width: 100px;
height: 100px;
background-color: #00F;
}
div:hover
{
height: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
So far I've only tested firefox & chrome, but it appears that you can get the current CSS height via JS.
I can't think of a reason why the browser wouldn't report the change in styles to the DOM during a CSS transition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With