Tuesday, May 20, 2014

Changes 5/20/14

jQuery:

  • Made my homepage just a bit more MLG
  • It was really frustrating, though.  I've been learning about onclick events, setTimeout(), element creation, image loading, and other stuff for the last two days, and by far the most frustrating stuff has just been the wierd quirks in javascript
  • For example, you cannot get the width or height of an image directly, only after it has been added to the page.  You also have to make at least one integer a float when dividing in order to get a decimal answer (seen when setting the height variable in mlg.js).
  • The setTimeout method was also really confusing because you can't pass a variable into the method within setTimeout, or it will not delay.  I was trying to pass this  in and it would not work.  It took me like 20 minutes to figure out the proper way to do it, even with googling, which ended up being setTimeout(function() { element.remove(); }, 125); where element = $(this).
  • Getting the cursor position from the mousemove event was also really confusing, as a guy on stackoverflow said that you needed to use event.offsetX to get mouse position from the event variable.  Then someone else said that on firefox, you needed to use event.layerX.  I tried both of these and neither worked, so I investigated and I believe that these two methods are for getting mouse position relative to an element, whereas I wanted location relative to the page.  I ended up using event.pageX, which I should have just done from the beginning.
  • All this stuff can be seen in the file here (UPDATE: changed to mlg_old.js), which is loaded into index.html

No comments:

Post a Comment