If you want to implement it from scratch, you could use CSS with opacity or color depending on how you want the fading to be. It is not difficult, but you need to understand how to manipulate element properties that you are working on. Also, it requires setTimeout to imitate the animation (should not use setInterval because you will have to keep the id of setInterval in order to clear it). If you show your work (your code), I could help you correct it. I do not want to give you the whole code for the animation because there are too many ways to implement it.
You could see some code I implemented from scratch to manipulate color (not opacity) at here (unfinish site and don't know when). Hover your mouse over the top square blocks and move the mouse out, and you will see what I mean. You can view the js source by using 'view source' on your browser.