This snippet listens for scroll events using addEventListener, sets a delayed timeout function to run a few milliseconds after the event, but with each scroll event it clears that timeout function so it doesn’t run.
Get the size of an image
These snippets will get the height and width of an image, one when it is loaded and another when the image is not loaded yet.
Check if the given number is odd
Check whether a number is odd or even using the modulo (%) operator. Return true if the number is odd, false if the number is even.
Selecting Elements By Class Name
To select elements by a given class name, you use the getElementsByClassName() method
Stop an iframe or HTML5 video from playing
This snippet stops or pauses YouTube, Vimeo and HTML5 videos when the content area is close
Resize an iframe to fit its content
This snippet gets the height of an iframe’s content and then sets the height of the iframe to match.
Calculate the nth root of a given number
Use Math.pow() to calculate x to the power of 1/n which is equal to the nth root of x.
Selecting an Element By Id
Select an element that matches the id using the getElementById() method.
Get the amount of time from now for a date
Here is a vanilla JS alternative to the moment.js timeFromNow() method.
Serialize form data into a query string
This function serializes the form data which consists of names and values of its fields.