2007/02/01 10:15
이정도만 보면,,^^; 서로 중복되게 올리는 경우도 있습니다. 참고,,
RSS 구독해서 전체글 쭈~욱 훑어 보니,

또, 눈만 높아져 있네요_-_;;


2006/11/06 10:07

CSS Photo Shuffler

A Javascript + CSS replacement for Flash photo fading slideshow. Inspired by Richard Rutter's image fade demonstration.

Example

Oregon Coast

The XHTML

Just like Richard's setup: an image in a div

<div id="photodiv"><img id="photoimg" src="bb3d0d6134.jpg" /></div>

The XHTML contains the image that will be both the first and the last image shown. The other image source values are put into the javascript routine.

The Setup

The customization section lets you set up how many photos in the deck and how many times you want to run through the deck.

var gblPhotoShufflerDivId = "photodiv";var gblPhotoShufflerImgId = "photoimg"; var gblImg = new Array(  "78ebdaf8bc.jpg",  "3523869ba4.jpg",  "fabcf2f7ce.jpg"  );var gblPauseSeconds = 7.25;var gblFadeSeconds = .85;var gblRotations = 1;

Specify unique IDs for your image and div. Load up the array with source paths to images to place into the rotation.

Pause seconds and fade seconds are pretty self-explanatory. I like fades to be between .75 and 2 seconds. Regardless of how long you choose to fade the image, I compute a fade call at 30fps, so even excruciatingly long fades have fairly smooth transitions.

Rotations allows you to move through the deck multiple times. It accepts a value of zero, meaning show each image in the deck then stop.

The Fade

You can hook the photoShufflerLaunch routine into your onload event by whatever means you prefer. It will load the first image from the array into the div background and pause the specified number of seconds.

When the timer pops, the image will fade to reveal the div background.

function photoShufflerFade(){  var theimg = document.getElementById(gblPhotoShufflerImgId);	  // determine delta based on number of fade seconds  // the slower the fade the more increments needed  var fadeDelta = 100 / (30 * gblFadeSeconds);  // fade top out to reveal bottom image  if (gblOpacity < 2*fadeDelta )   {    gblOpacity = 100;    // stop the rotation if we're done    if (gblImageRotations < 1) return;    photoShufflerShuffle();    // pause before next fade    setTimeout("photoShufflerFade()",gblPauseSeconds*1000);  } else  {    gblOpacity -= fadeDelta;    setOpacity(theimg,gblOpacity);    setTimeout("photoShufflerFade()",30);  // 1/30th of a second  }}

The Shuffle

Then I shuffle the deck.

Once the div background is fully revealed, I pop the background image source value into the (transparent) image source attribute and set the opacity of the image to 100 percent. The image is fully opaque and completely hides the div background, which at this point, is the same photo.

function photoShufflerShuffle(){  var thediv = document.getElementById(gblPhotoShufflerDivId);  var theimg = document.getElementById(gblPhotoShufflerImgId);  // copy div background-image to img.src  theimg.src = gblImg[gblOnDeck];  // set img opacity to 100  setOpacity(theimg,100);  // shuffle the deck  gblOnDeck = ++gblOnDeck % gblDeckSize;  // decrement rotation counter  if (--gblImageRotations < 1)  {    // insert start/final image if we're done    gblImg[gblOnDeck] = gblStartImg;  }  // slide next image underneath  thediv.style.backgroundImage='url(' + gblImg[gblOnDeck] + ')';}

I set the background image to the next photo in line, and pause the specified number of seconds.

When the timer pops, the image will fade to reveal the div background. I work through the rotation the specified number of times, then show the first photo again and stop.

Caching

As my Stanford professors were wont to say, ensuring that a photo is loaded before fading to it "...is left as an exercise for the student."

Since the photos are loaded as div backgrounds for the duration of the pause, they have a few seconds to load. I haven't seen any broken images yet, but I have fairly decent bandwith capabilities at home.

Accessibility, Compatibility

  • Javascript off - first image appears without animation.
  • Javascript and CSS off - first image appears without animation.
  • CSS off - div extends out and the background repeats
  • Images off - Alt text is displayed
  • application/xhtml+xml - works fine, does not use document.write()

In practice, I put the CSS and JavaScript into their own files. For this demo page, I've included everything together as a unit for improved portability.

2006/11/06 09:58

Top 10 CSS image gallery tutorials

November 3rd

There are many tutorials out there on how to create your own image gallery. There are simple ones made from pure CSS, and there are complex ones using css and javascript. By the end of this article you will have the information necessary to start building your own photo gallery.

The first tutorial is from cssplay and is one of my favorites around. They have a very elegant and simple image gallery. Your images are separated into different sections (people, plants, animals, etc) and all your images for each section listed nicely underneath. As you hover over each image it expands double it's size so you can take a better look at each image before you view the full version. The interface is very clean and simple to use, I recommend taking a look at this one.





Our next example is from the css library at dynamicdrive . This is a more basic image gallery setup, it just involves thumbnails on the site and you hover over each one the full image is displayed on the right side of the screen. The code for this one is simple and is good for beginners to understand whats happening.






This next example is another simple one from dasme.org called ImageGal. This image gallery uses javascript along with CSS, but again is a simple gallery that would be good for beginners looking for something similar to this. To use it you simply click on a thumbnail and the full size image is loaded right onto the screen. Again nothing too complicated but something for you beginners to look at.






Here we have another creative one from cssplay. This one isn't so much an image gallery as it is a mesh of seven different pictures set to interact in a kind of accordion fashion. All the images are stacked on each other horizontally and as you hover over each image it expands from it's current position, I don't see this being useful with a lot of images but it's a creative little one.






Project Seven has one slightly similar to dasme.org but they did theirs right. Your images are displayed vertically along the left side of your screen one on top of another. As you scroll through them and click one, the image along with a description are loaded right there for you. It's minimal but is very well designed.






This next one is a remake of the first gallery on this list and again it's from cssplay. The main design is basically the same with the different tabs on top for the sections. As you hover over images they no longer expand for easier viewing, the background of the images is just changed to black. I really liked the expanding images on hover from the first one I wish they would have kept it in the remake. In this new one when you click an image the full size is loaded right into the window, then if you click it again it will take you right back to the list of images. I really like this feature in the new one, it makes it more user friendly not having to redirect to view the full size image. This one is also worth looking at.




This next one is from joshuaink.com and has a nice clean layout, when you hover over an image you are shown the description for the image, and when you click an image you are redirected to the full size image with the description on top. It's not too complicated so this would be another good one for beginners to look at and mess around with because there's not a lot of extra code to get confused about.


This image gallery from tkjdesign.com is another one that uses javascript in addition to css to display the images. You have a set of images on the left hand side of your screen and as you hover over them you only get a white border, but as you click each image the page background is dimmed, and the full size image is loaded right onto the screen. To get back to the images simply click the image your viewing and it will be closed. This one is a more advanced gallery and also worth looking at.





Our next tutorial is from webreference.com is another simple one which takes some of your images, displays them as thumbnails and as you hover over each one the full size image is displayed with a little description. It's not the nicest layout but again for you beginners this is another good place to start.





Our last tutorial is another from Project Seven and this is one of the more advanced ones. This one has some similarities to cssplay's image gallery but the way in which it loads each image as you click it is unique. It loads the image then re sizes it from 0% to 100% right in front of you, which isn't really complicated for more advanced users but it gives it a nice fun feeling.


If you have a custom image gallery, or know of one that I missed worth mentioning leave a comment and let me know.


카테고리