Forum Moderators: open
yt=(yt/1)+yi
the book i'm reading doesnt explain what its doing and the author didnt respond to my email, its in a function that moves a layer to simulate scrolling
yt is the current top of layer
yi is the increment to scroll
cheers
[BLUE]"290"/1 --> 290[/BLUE] but
[BLUE]"hello"/1 --> NaN (not a number)[/BLUE] I'm not sure it'll work properly unless you are using IE-only properties.
style.left and top properties usually contain the units too:
[BLUE]"290px"/1 --> NaN[/BLUE] Use parseInt instead
[BLUE]parseInt("290px") --> 290[/BLUE]
n = Number("123")
You'd only use eval for actual calculations in string form:
n = eval("4+6")
The problem with eval (or one of them) is that, if the string contains any non-digit characters, you'll end up referencing a non-existent, or invalid variable, resulting in a script error rather than just plain NaN, which can be tested for.
var newval = val - 0; // convert val to number
var newval = val + ""; // convert val to string