Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

After going away on a trip to the mountains and testing out my Travel µBlog software for the first time it was clear that some improvements were needed in terms of how photos are displayed. The main issue I noticed was that photos taken on a Galaxy S6 were 1080p and hence wide screen. This didn't play well with the 4:3 aspect ratio sized photo boxes used on the blog.

I decided that the best way to handle this was to have these widescreen photos be scrollable somehow. I tried out scripts like panoramaviewer.js and jquery.panr as well as a few others but none of them were exactly what I was looking for. So after a little bit of light reading I decided to create my own jQuery UI Plugin.

Introducing the jQuery UI Photoboxr Plugin...
screenshot.jpg


This plugin creates a constant ratio (4:3) box around a photo. It determines whether the photo is landscape or portrait and lets you scroll it accordingly if its dimensions exceed the size of it's wrapping DIV.

There are overlay indicators for scroll direction which also double up as on/off toggles for scrolling. There is integration for Fancybox to create galleries and photo pop ups too.

Using it is easy. All you need to start is an DIV element with a size defined. This will be the container for any images added by the plugin.
 HTML
<div id="photoboxr-container" style="width: 100%;">
</div>


Then the JavaScript is similar to any other jQuery UI plugin, simply call the .photoboxr() method to initialise it. I create an Image object but it could be done on an <img> element too. After the plugin is initialised, the 'wrapper' method is used to fetch the wrapping DIV around the image, which can then be added to the container.
 JavaScript
var container = $('#photoboxr-container');
$(new Image()).photoboxr({
src: 'fog_panorama.jpg',
wrapSizingClass: 'ui-pbxr-half'
})
.photoboxr('wrapper')
.appendTo(container);




There are other options available that can be passed to the plugin, these are documented on GitHub.

This plugin works well for me, it's not as versatile as some of the other panoramic view plugins out there, but that was not the point of it. There are some minor issues with it still that I will address over time so keep an eye out for future updates.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.