A very simple, pure JavaScript carousel written in 3 days for an interview. I promise I have not changed this since the interview.
This carousel must:
- Should be written using HTML(5)/CSS(3)/Javascript.
- Should be full-frame (fill the whole browser window).
- No JS library (ex: YUI, jquery, backbone, etc.).
- Must work in either latest Chrome or Firefox (Bonus for extra compatibility).
- The rules are intentionally vague.
- Implementation does not have to be perfect, but should be functional.
- Allowed to use sample code from the web, as long as the majority of the solution is written by you.
- Your solution will be evaluated more on style and architecture than performance.
This is a click and drag version that is fully linted and takes event propagation into account. Some key features to note:
- This uses propagating mouse events to determine which elements the mouse is currently in so that the carousel does not accidentally stop.
- This code is fullly linted
- This code uses the revealing module pattern, which allows for hot fixes and method overwrites from other programs
- All assets are lazy loaded (loaded after DOM ready)
- This code, for simplicity, stays away from the use of this, call, and apply (as recommended by Douglas Crockford).
- The log function is used so that browsers that don't have a console are not affected (as recommended by Paul Irish).
- If a class is not instantiated with the new operator, the class will return itself instantiated with the new operator to keep the prototype chain
- The onReady event is handeled as modernly as possible, and falls back to window onload for older browsers.