I've two divs positioned absolutly and I position them relative to each other. When width
of one is change, then i recalculate and set positions. While I use css3 transition on ' width
' property, when i try to get ' width
' of animated one, it gives me the current value on dom. But i want to get the target value of transition to set positions correctly on begin of transition effect. Is this possible to get the target value via javascript or other ways?
EDIT
Below is a jsfiddle demonstrates my issue. It alerts '100px' but I need to get '300px'.
Thanks.
That's because .css('width')
is calling getComputedStyle
on the element, which does return the transitioning value. If you did directly access the style, you would get what you just had set:
document.getElementById('transition_div').style.width
$('#transition_div').prop('style').width
$('#transition_div')[0].style.width
( updated fiddle )
You could use the transitionend
event: ( see for equivalent prefixed vendor )
$('#transition_div').css('width', 300).on("transitionend", function () {
alert($(this).css('width'));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.