I have a function that repositions the image so when you zoom in/out it stays centered on the same point. I wanted to be able to call it to reposition for a move that only had a horizontal vector, so I made it check to make sure there was a value for each of the x and y coordinates before it tried moving the image on that vector. I passed in an empty string when I didn't want to make a move on that vector. The problem came in to play when I zoomed out to the max and the image's position on the short dimension became 0. I want to move the image to 0 on that vector, but my test for no value was catching the 0 and calling it "nothing", just like ''.
Once I tracked this down, the solution was simple. Just use the "really equal, I mean it for reals" operator; a.k.a. "===".
if (left != '' || left === 0) { do stuff; }A more appropriate way to do this might be to have a real value like "nochange" mark when I don't want to do anything with that vector, but I did this because I didn't want to find all the places where I used '' and change them.
0 comments:
Post a Comment