Binary Code

A whole lot of nought thought by Chris Cummer

Fix for uGallery

On a current project I’m working on, we’re using uGallery to implement an image carousel. Despite the JS code being a bit rough it’s very easy to integrate and the output is quite elegant. I like it a lot.

Unfortunately the current version of uGallery (1.1) has a minor bug. If you’re displaying fewer thumbnails whose width will exceed the interior of the thumbnail viewport, the horizontal scrolling goes wonky. This wee patch fixes that issue.

In uGallery.js wrap the margin calculation and style assignment in this conditional:

1
2
3
4
5
// Only bother to scroll the content if its area is greater than the viewport
if ( contentWidth > viewWidth ) {
    var margin = -Math.round( ( e.clientX / viewWidth ) * movableWidth ) + 20;
    thumbs.css( {"margin-left": margin+"px"} );
}