jueves, 8 de octubre de 2015

Código de ejemplo para prettyPhoto

prettyPhoto Example

A gallery that does more than images

Introduction

Lightbox is a common way to easily create an image gallery. Lightbox used to use two JavaScript libraries named Prototype and Scriptaculous. These are both good. HoweverjQuery seems to be the dominant library. Lightbox has recently switched to jQuery.
Even so it doesn't have some of the capabilities to show many different kinds of content (like video or whatever). I'm showing you how to do a similar thing with prettyPhoto which is also some JavaScript built on top of the jQuery library. Once you have the jQuery library installed in your site you will have a lot of other options to add other interactivity to your site. There are literally thousands of tutorials and extensions for jQuery.
Here's how it works (for more in-depth tutorial see the prettyPhoto web site)

Basic Concept

The basic idea is that you download some JavaScript, CSS and Image files and write your links with a specific syntax and add a bit of JavaScript to your page and then your gallery works. What it essentially does is hijack a link you write to a large image and instead of letting the browser go to the image it grabs the image and displays it on top of the current page with a partly see through grey background between the image and the page.
NOTE: you can use more than just images in the gallery. You can use it to show video, Flash or other sites. Read the documentation for more information.

Single Image

This is a simple example of what you would do for an image (once you've included all of the other files and script tags needed) to show it in prettyPhoto.

  <a href="images/theIMG.jpg" rel="prettyPhoto" title="title here" >  
      <img src="images/theIMG_tb.jpg" width="80" height="80" alt="Monkeys" />
  </a>  
  

Image Gallery Tutorial

  1. Download the files you will need. Go to this link and click on the Production Version Compressed link.
  2. The file is a .zip file. Unzip it.
  3. Copy the js, images and css folders to your site. If you already have js, images or css folders then just copy the contents of these folders to your existing folders.
  4. Add the following to your HTML page inside the <head> element so that it uses the css and JavaScript files you just downloaded:
      <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
      <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
      <script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
      
    Instead of linking to a downloaded version of jQuery I would recommend linking to a CDN hosted version like below. The only thing to worry about is that a brand new version of jQuery might break the code. So test it. The version shown works.
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript" type="text/javascript"></script>
  5. Add this right before the closing body element on the page:
    <script type="text/javascript" charset="utf-8">
                   $(document).ready(function(){
                     $("a[rel^='prettyPhoto']").prettyPhoto();
                   });
                 </script>
                 </body>
    
    Image of the script tag for pretty photo
    prettyPhoto shows links to twitter and facebook by default. If you don't want them to show up the add in an options object to the prettyPhoto line,like this instead of the line that starts:
    
      $("a[rel^='prettyPhoto']").prettyPhoto({social_tools:''});
    
  6. Add your thumbnails to the page with normal HTML.
  7. Make sure the link in the href attribute points to the large version of the image
  8. Add a rel attribute to your <a> element with the following syntax rel="prettyPhoto[galleryName]"
    Here's a photo:
    picture of

    Example:
    <a rel="prettyPhoto[myGallery]" title="Cocoa Pod" href="large1.jpg">
          <img alt="picture of cocoa pod split open" src="thumb1.jpg" />
      </a>   
      
      <a rel="prettyPhoto[myGallery]" title="Man with a Parro" href="large2.jpg">
          <img alt="Man with a Parro" src="thumb2.jpg" />
      </a>
      
      <a rel="prettyPhoto[myGallery]" title="Red Umbrella" href="large2.jpg">
          <img alt="Red Umbrella" src="thumb2.jpg" />
      </a>
      
    Notice that the rel attribute is exactly the same each time. It doesn't change
You of course would just link to your own images. Remember that there are two images used. One is the thumbnail which is included with the img elment. If the user doesn't have Javascript then the big image will just show in a new page by itself.

Example Gallery

That’s all folks. Hopefully your gallery will be working shortly.

Fuente: http://www.teachingmultimedia.com/mmp240/prettyPhoto/#prettyPhoto

No hay comentarios:

Publicar un comentario

Jesús Moreno - Ingeniero Ténico Informático - consultor Informático

Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...