Alexander Solonik Alexander Solonik - 3 months ago 23
Javascript Question

understanding safari SVG redraw bug fix.

I was just going through THIS snap sbg demo and i came across the following lines of code:

var flag,
len = Snap.path.getTotalLength(pth.attr("d"));
Snap.animate(0, len, function (l) {
// Safari bug workaround: forcing redraw
g.attr({width: 100 + (flag = !flag ? 1e-5 : 0) + "%"});
//
var dot = pth.getPointAtLength(l);
flight.attr({
d: pth.getSubpath(0, l)
});
pln.attr({
transform: "t" + [dot.x, dot.y] +
"r" + (dot.alpha - 90)
});
gr.attr({
transform: getShift(dot)
});
}, 10000);


Now i am not quite understanding the below line of code:

g.attr({width: 100 + (flag = !flag ? 1e-5 : 0) + "%"});


What exactly is
1e-5
? can somebody explian ?

Answer
flag = (!flag ? 1e-5 : 0) + "%"

is the same as:

if(!flag) {
    flag = 0.00001; //1e-5 is the scientific notation for 1^-5
} else {
    flag = 0;
}

flag = flag + "%";