Prevent slide range overrun by checking the slide boundary.

It is quite verbose, but it prevents the issue #85 as well as the bug that I could swipe to non-existing slide 2 when I had just two slides.

The original code didn't check the range and it could issue `scroll(-1)` or `scroll(2)`.