Skip to content Skip to tags Skip to twitter news Skip to blog roll Skip to categories Skip to archives Skip to recent posts

October 2, 2007

jQuery: jqGalViewII (Photo Gallery)

This is the jQuery Gallery View II plugin (jqGalViewII) which takes a list of your images and creates an easily styles photo gallery. This plugin will preload all of your larger images for faster viewing.

The Head

JavaScript:
  1. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
  2. <script type="text/javascript" src="common/js/jqGalViewII.pack.js"></script>
  3. <script type="text/javascript">
  4. $(document).ready(function(){
  5.     $('#demo').jqGalViewII();
  6. });
  7. </script>

HTML:
  1. <style type="text/css" media="screen">
  2. <!--
  3. @import url("common/css/jqGalViewII.css");
  4. -->
  5. </style>

The Body

HTML:
  1. <ul title="My Gallery">
  2.     <li><a href="http://lh6.google.com/sterling.benjamin/RuyW_7tKn8I/AAAAAAAAAVc/opzOXldgJ0Y/DSC_0001.JPG?imgmax=800"><img src="http://lh6.google.com/sterling.benjamin/RuyW_7tKn8I/AAAAAAAAAVc/opzOXldgJ0Y/s72/DSC_0001.JPG" alt="Yes, I do know what I am doing!" width="72" height="48" border="0"/></a></li>
  3.     <li><a href="http://lh5.google.com/sterling.benjamin/RuyYPrtKn9I/AAAAAAAAAWE/Y1kITpSTFXI/DSC_0025.JPG?imgmax=800"><img src="http://lh5.google.com/sterling.benjamin/RuyYPrtKn9I/AAAAAAAAAWE/Y1kITpSTFXI/s72/DSC_0025.JPG" alt="Hey, it is better then reversible diapers!" width="72" height="48" border="0"/></a></li>
  4.     <li><a href="http://lh4.google.com/sterling.benjamin/RuyZObtKoAI/AAAAAAAAAWc/dDMbJK0jSlw/DSC_0004.JPG?imgmax=800"><img src="http://lh4.google.com/sterling.benjamin/RuyZObtKoAI/AAAAAAAAAWc/dDMbJK0jSlw/s72/DSC_0004.JPG" border="0"/></a></li>
  5.     <li><a href="http://lh6.google.com/sterling.benjamin/RuyZa7tKoBI/AAAAAAAAAWo/dmnMNJS2nPI/DSC_0005.JPG?imgmax=800"><img src="http://lh6.google.com/sterling.benjamin/RuyZa7tKoBI/AAAAAAAAAWo/dmnMNJS2nPI/s72/DSC_0005.JPG" border="0"/></a></li>
  6.     <li><a href="http://lh3.google.com/sterling.benjamin/RuyZnLtKoCI/AAAAAAAAAWw/1TD-_nNT8PA/DSC_0006.JPG?imgmax=800"><img src="http://lh3.google.com/sterling.benjamin/RuyZnLtKoCI/AAAAAAAAAWw/1TD-_nNT8PA/s72/DSC_0006.JPG" width="72" height="48" border="0"/></a></li>
  7. </ul>

And that would produce the following:

  • Yes, I do know what I am doing!
  • Hey, it is better then reversible diapers!
  • Is he going to eat me?!
  • It's like talking to a wall!!!
  • This is my seductive look! It works on all the boys.
  • You won't like me when I'm angry!
  • It is out of focus; let me help.
  • I always have to carry the conversation; they never say anything.
  • I SAID CLOSER!!!
  • I think I may be getting the upper hand here...
  • I'm being attacked and your taking pictures?
  • Yes, I do know what I am doing!
  • Hey, it is better then reversible diapers!
  • Is he going to eat me?!
  • It's like talking to a wall!!!
  • This is my seductive look! It works on all the boys.
  • You won't like me when I'm angry!
  • It is out of focus; let me help.
  • I always have to carry the conversation; they never say anything.
  • I SAID CLOSER!!!
  • What way is this supposed to go?
  • I think I may be getting the upper hand here...
  • I'm being attacked and your taking pictures?

The Downloads

Download zip with demo and styles: http://bs-jquery-plugins.googl.....II.1.0.zip
The jQuery core is available at: http://code.google.com/p/jqueryjs/downloads/list.



Pages: « 13 12 11 10 [9] 8 7 6 5 4 31 » Show All

121 Responses to “jQuery: jqGalViewII (Photo Gallery)”

I love your script. However, I am trying to use it using about 100 pictures for the gallery. Trying to preload all those images causes a lot of resources to be used. How can I remove the preload option?

Thanks,
Steven

@Colin: http://monc.se/kitchen/146/gal.....ge-gallery

@Fernando: sorry for the delay in getting back with you, for some reason you went into spam.

I am not a 100% what you are trying to do, do you have a link to where I can see what you are at now? With that said, the .onload should work in IE even if it is cached, but I could be wrong.

Hi Benjamin,

great job indeed !

I tried to take out some hints from your work:

suppose you have a page in which there are many links (thumbnails or other stuff) to images. When one of those link is clicked the src attr of the big image is set to get it displayed CENTERED in a div.
The first issue to solve was to clearly get when the image has fully loaded.
Mozilla always triggers a "load" event, but IE doesn't if the image is in the cache yet. So, to test img.complete, I have first to wipe out the image from the DOM and then reinsert it and set its src attr.
Another approach could be to install a listener on the image (I found some clues searching the web).
Both of them work meaning that I have a trigger when the image if loaded.

At that point the simple part would come, but...
before to do a $(....).show('slow'.... I tried to get image width and height (the height is the problem, to center horizontally CSS margin: auto suffices !) using, like in your code, height property.

In mozilla it works perfectly but in IE it got always 0 for the height.

I solved assigning the image to the background of the div, but this seems a workaround rather than a solution.

Can you please help, suggesting other approacches also ?

Here some code:

CODE:
  1. jQuery(document).ready(function() {
  2.         $('').appendTo('#imgBig').hide();
  3.         $('').appendTo('#tit').hide();
  4.  
  5.         var imgContainer = $("#big");
  6.         var immage = $("#big img");
  7.  
  8.      function addEvent(obj, ev, fn) {
  9.      if (obj.addEventListener) {
  10.      obj.addEventListener(ev, fn, false);
  11.      } else if (obj.attachEvent) {
  12.      obj.attachEvent('on' + ev, fn);
  13.      }
  14.      }
  15.  
  16.      function imgLoad(e) {
  17.      if (!e) var e = window.event;
  18.      // note: I don't know which is correct, but moz reports e.target as being the document and e.currentTarget as the image
  19.      // opera says both e.target and e.currentTarget are the img - which is what I would've expected...
  20.      // IE doesn't have the concept of a currentTarget, but srcElement (it's version of target) points at the img element
  21.      var target = e.currentTarget || e.srcElement;
  22.  
  23.      //alert('Loaded:' + target.height + ' '+immage.get(0).height);
  24.      imgContainer.css({'top': (550 - immage[0].height)/2+'px','left': (560 - immage[0].width)/2 + 'px'})
  25.                       .show(1500,function() {
  26.                          $("#titolo").fadeIn('slow');
  27.                     });
  28.      }
  29.  
  30.      addEvent(immage[0], 'load', imgLoad);
  31.  
  32.         immage.attr("src", './imgstore/coperta.jpg');
  33.         imgContainer.show(800);
  34.  
  35.         $("#links-container img").click(function() {
  36.           var ll = $(this).parent().attr("href");
  37.           $("#titolo").text($(this).attr("title")).hide();
  38.  
  39.           imgContainer.hide(800, function() {
  40.                  immage.attr("src", ll);
  41.           });
  42.           return false
  43.         }); //click
  44.  
  45.      });

or wiping out and in the img from the DOM:

CODE:
  1. jQuery(document).ready(function() {
  2.         $('').appendTo('#imgBig').hide();
  3.         $('').appendTo('#tit').hide();
  4.  
  5.         var imgContainer = $("#big");
  6.         var immage = $("#big img");
  7.  
  8.         var MostraImg = function() {
  9.         // alert(immage[0].height);
  10.            imgContainer.css({'top': (550 - immage[0].height)/2+'px','left': (560 - immage[0].width)/2 + 'px'})
  11.                  .show(1500,function() {
  12.                     $("#titolo").fadeIn('slow');
  13.                     });
  14.        // alert(immage.height());
  15.  
  16.         }
  17.  
  18.         immage.attr("src", './imgstore/coperta.jpg');
  19.         imgContainer.show(800);
  20.  
  21.         $("#links-container img").click(function() {
  22.           var ll = $(this).parent().attr("href");
  23.           $("#titolo").text($(this).attr("title")).hide();
  24.  
  25.           imgContainer.append('').hide(800, function() {
  26.                immage.remove();
  27.                immage = $("#big img");
  28.            immage.attr("src", ll);
  29.  
  30.            if (immage[0].complete) {
  31.                MostraImg();
  32.               }
  33.              else {
  34.                immage.bind('load',MostraImg);
  35.            }
  36.           });
  37.           return false
  38.         }); //click
  39.  
  40.      });


Thank you in advance and sorry for my bad English (greetings from Italy)

Fernando

Swazi: yes, you will just need to play with css files. Give it a try and if you run into any issues drop me a line.

Is there a way to make the thumb images postion beside the big selected phot instead at the bottom?

[...] jQuery lightBox plugin. jQuery Image Strip. jQuery slideViewer. jQuery jqGalScroll 2.0. jQuery - jqGalViewII. jQuery - jqGalViewIII. jQuery Photo Slider. jQuery Thumbs - easily create thumbnails. jQuery jQIR [...]

Huh, I just realized it would easier to make the thumbnails with css:

CODE:
  1. .gvIIItem img { width:50px; height: 50px; }

All I need to do is make sure the fulll-size images have the same heights & widths. Hindsight is 20-20!

Thank you! This is great.

I had an idea that for small galleries it would be nice to generate thumbnails on the fly from a list of full-size images. I've been working on integrating easyThumb with your gallery but I haven't quite figured out how to do it yet.

Do you think this is possible? Is there a way to force jqGalViewII to wait until the thumbnail code is generated?

[...] lightBox plugin.jQuery Image Strip.jQuery slideViewer.jQuery jqGalScroll 2.0.jQuery - jqGalViewII.jQuery - jqGalViewIII.jQuery Photo Slider.jQuery Thumbs - easily create thumbnails.jQuery jQIR [...]

Pages: « 13 12 11 10 [9] 8 7 6 5 4 31 » Show All

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

RSS Feed Link

42 queries. 1.838 seconds. Powered by WordPress visitor stats