{"id":1785,"date":"2010-01-31T21:59:26","date_gmt":"2010-02-01T03:59:26","guid":{"rendered":"http:\/\/www.cyberward.net\/blog\/?page_id=1785"},"modified":"2022-10-10T13:02:32","modified_gmt":"2022-10-10T18:02:32","slug":"bgstretcher2","status":"publish","type":"page","link":"http:\/\/www.cyberward.net\/blog\/code\/bgstretcher2\/","title":{"rendered":"bgStretcher2"},"content":{"rendered":"<p><a href=\"http:\/\/www.cyberward.net\/photography\/\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1777\" data-permalink=\"http:\/\/www.cyberward.net\/blog\/2010\/02\/full-screen-slideshow-in-javascript\/screen\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?fit=500%2C396\" data-orig-size=\"500,396\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Gallery Slideshow Screen Shot\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?fit=240%2C190\" data-large-file=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?fit=500%2C396\" class=\"alignnone size-full wp-image-1777\" title=\"Gallery Slideshow Screen Shot\" src=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?resize=500%2C396\" alt=\"\" width=\"500\" height=\"396\" srcset=\"https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?w=500 500w, https:\/\/i0.wp.com\/www.cyberward.net\/blog\/wp-content\/uploads\/screen.jpg?resize=300%2C237 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Here is a full screen <a href=\"http:\/\/cyberward.net\/photography\/\">slideshow<\/a> in Javascript, without using flash, and I wanted to tell you how I did it, and how you can do it too. I will talk a bit about Javascript here, but you will be able to download the jQuery plugin I have without needing to know much, if all you want is to implement the gallery.<\/p>\n<p>First of all, I wanted to use the <a href=\"http:\/\/jquery.com\/\">jQuery<\/a> library. It is a small compact little library that makes operations like selecting parts of an HTML document easy. It is cross platform too, so the likely hood if it working on Safari, IE, and Firefox is high.<\/p>\n<p>Next, I went looking for a jQuery plugin that did the image scaling already.  I ended up with a plugin called <a href=\"http:\/\/www.ajaxblender.com\/bgstretcher-jquery-stretch-background-plugin.html\">bgStretcher<\/a> from ajaxBlender.com. The main idea behind this plugin, is that it takes an image, places it in its own div that appears to be the background, then stretches the image to fill the browser window. This plugin was close to what I wanted, but it was missing a few things. First, I wanted to be able to navigate through the images with buttons, not just a slideshow. That was a simple matter of adding some  onClick handlers and calling new methods in the javascript. jQuery has the ability to ask for the .next() or .previous() html item, so once I had the current image selected, it was easy to find the next or previous.<\/p>\n<p>Then I wanted to be able to handle albums, not just one list of images. That was harder. Instead of just supplying a list of images to bgStretcher, you now pass albums to bgStretcher2. You identify the album before you pass the list of images.<\/p>\n<pre>$(document).bgStretcher({\n  albums:{'Landscapes':['images\/landscape1.jpg', 'images\/landscape2.jpg', 'images\/landscape3.jpg'],\n          'People':['images\/people1.jpg', 'images\/people2.jpg', 'images\/people3.jpg'],\n          'Flowers':['images\/flowers1.jpg', 'images\/flowers2.jpg', 'images\/flowers3.jpg'],\n          'Night':['images\/night1.jpg', 'images\/night2.jpg', 'images\/night3.jpg']},\n  album: 'Landscapes', imageWidth: 1200, imageHeight: 800\n\t});<\/pre>\n<p>This way you pass a name of the album that I use to assign all images in that album with that class. I then can use a jQuery selector to select all images with that class. Now I can navigate from image to image within the album. Note: One thing that is brittle about this, is that your menu items need to match these album names.<\/p>\n<pre>var current = $(containerStr + ' LI.'+$.fn.bgStretcher.settings.album).filter('.bgs-current');<\/pre>\n<p>This ends up more like this:<\/p>\n<pre>var current = $('#bgsretcher LI.Landscapes').filter('.bgs-current');<\/pre>\n<p>That line will select within the bgstretcher div all the LI elements with a class of Landscapes. It then narrows in on the currently selected one with the filter. I could have done it all with one string, but thought the addition of the filter made it clearer.<\/p>\n<p>Now, if you are looking at the HTML and not finding a bgstretcher div, or the LI elements that contain images, don&#8217;t worry, it&#8217;s because they are not there. At least not in the static page. They get generated in the _genHtml() function at start.<\/p>\n<p>The last thing to do was to modify the next and previous functions so that they would stick to selecting items within the current album. That turned out to be similar to the selector above for curent, but I just needed to get the &#8216;:first&#8217; element that had the album class attached.<\/p>\n<p>Once the Javascript was working I wanted to spruce it up a little bit. I used a menu plugin called <a href=\"http:\/\/www.gmarwaha.com\/blog\/2007\/08\/23\/lavalamp-for-jquery-lovers\/\">lavalamp<\/a> from Ganesh. In its default config, the plugin has a orange image around the menu. I kind of liked it, but it wasn&#8217;t quite the right size for the items I had, so I had to disable it. I think you could generate another image the right size and make it work, but I didn&#8217;t get to trying that.<\/p>\n<p>The lavalamp plugin also uses another plugin, called easing. It provides the bouncing effect you see when moving the mouse around the menu. I think this is a great example of how well plugins work with jQuery. The base language extension is small and compact, but you can easily add functionality with plugins, and they can even interact together.<\/p>\n<p>If you would like to use this code to create your own full screen slideshow image gallery, I have provided a download of the files required. I won&#8217;t get much into the details of installation because it is so simple. There is one index.html file, a css folder with the styling, and a js folder with the Javascript files. On my site I have a images folder that I placed all my images into, but for the download, I simply referenced some of my images from <a href=\"http:\/\/www.flickr.com\/photos\/v3ggi32u\/\">flickr<\/a> to make the download smaller. Now, remember, if you are putting this up, you might want to host the images locally, because it is actually against the terms of service of flickr to not link back from the image to flickr. I don&#8217;t have that linking ability in my script right now.<\/p>\n<p>The only thing that you need to do is prepare some images and change the list of albums and images in the index.html file. Also, remember that the album names, and the menu titles need to be the same, so don&#8217;t forget to modify the menu too. That is just how the script works. You can add or subtract albums by adding or subracting more LI elements. Just follow the pattern in the index.html file.<\/p>\n<p>The last line in the images setup Javascript is the album to start on, and the images height and width. The images will size best if they are about the same size and about the height and width that you state in the file here.<\/p>\n<p><strong>Update (2011\/04\/03):<\/strong><\/p>\n<p>The code has been bumped to 2.2. I have added a property fitImageToBrowser and defaulted it to true. Seems most people would like their images to be full screen but not clip any of the image. Well, that&#8217;s just not possible. If you want to fit the long edge of the image to the long edge of the browser window and set the other to have the letter box effect, then this property is the one for you. If you liked the old functionality, just set it to false.<\/p>\n<p>Also, if you want to get rid of the lavalamp menu, then remove the script tag for it in the html. Then in the bgstretcher2.js file, comment the _configureLavaLamp() line. You can now style your menu however you would like.<\/p>\n<p>[drain file 17 show tableRow]<\/p>\n<table class=\"drainhole\">\n<tbody>\n<tr>\n<th><\/th>\n<th>Download Name<\/th>\n<th>Version<\/th>\n<th>Size<\/th>\n<th>Updated<\/th>\n<th>Hits<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Here is a full screen slideshow in Javascript, without using flash, and I wanted to tell you how I did it, and how you can do it too. I will talk a bit about Javascript here, but you will be &hellip; <a href=\"http:\/\/www.cyberward.net\/blog\/code\/bgstretcher2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":729,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"jetpack_shortlink":"https:\/\/wp.me\/PffAy-sN","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/pages\/1785"}],"collection":[{"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/comments?post=1785"}],"version-history":[{"count":9,"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/pages\/1785\/revisions"}],"predecessor-version":[{"id":3282,"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/pages\/1785\/revisions\/3282"}],"up":[{"embeddable":true,"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/pages\/729"}],"wp:attachment":[{"href":"http:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/media?parent=1785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}