When asking jQuery for a duration in CSS, it returns this value in seconds, e.g. 1.2s. Example here.
var d = $("div"),
propDur = d.css("animation-duration"),
propDurArr = propDur.replace(" ","").split(","),
propDel = d.css("animation-delay"),
propDelArr = propDel.replace(" ","").split(",");
console.log(propDurArr[propDurArr.length - 1]);
console.log(propDelArr[propDelArr.length - 1]);
Two questions for this:
ms)? For example: 1.2s -> 1200.For 2. you can easily remove the dot, like so:
propDel.replace(/(\s|.)/g,"").split(",")
But how do I make a condition like this:
if string contains dot
ADD 00
if string does NOT contain dot
ADD 000
Please reply to 1 and 2.
I decided to go with @RobG's comment that he hasn't posted as answer yet, so here goes. Quite simple and effective:
function toMS(s) {
return parseFloat(s) * (/\ds$/.test(s) ? 1000 : 1);
}
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