Refactoring thumbnail scroll code to fix jumps

Fixes #3230 and supersedes #3243.

This PR does a couple of things:

- Fixes thumbnail jumps as described in #3230 in a cleaner way than the previous PR, that is with less JavaScript (almost none, actually).

- Improves the thumbnail view by adding a bit more margin between the thumbnails. Also, the last thumbnail is given a larger bottom margin to make it look the same as the top of the thumbnail view.

- The code style for the piece of code this PR touches has been updated to adhere to the coding standards.