Advertisement
Guest User

Untitled

a guest
Feb 11th, 2011
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.74 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. //example: images = ["air.jpg", "evening.jpg", "penguin.jpg"];
  5. // insert your images here
  6. images = ["https://linuxfr.org/images/linuxfr2_moutain.png", "https://linuxfr.org/images/logos/DaLinux-LoftStory-frenchPage.png", "https://linuxfr.org/images/logos/linuxfr-ohl2.png"];
  7. </script>
  8. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  9. <script>
  10. function next() {
  11.     currentimage++;
  12.     if (currentimage >= images.length)
  13.         currentimage = 0;
  14.     fadeAndSet();
  15. }
  16.  
  17. function previous() {
  18.     currentimage--;
  19.     if (currentimage < 0)
  20.         currentimage = images.length - 1;
  21.     fadeAndSet();
  22. }
  23.  
  24. function fadeAndSet() {
  25.     $("#preimage").attr('src', images[currentimage]);
  26.     centerObj("#preimage");
  27.    
  28.     $("#image").fadeOut(1000, function() {
  29.         $("#image").attr('src', $("#preimage").attr('src'));
  30.         $("#image").show();
  31.         $("#image").css('left', $("#preimage").css('left'));
  32.     });
  33.     $("#preimage").fadeIn(1000, function () {
  34.         $("#preimage").hide();
  35.     });
  36. }
  37.  
  38. function centerObj(sel) {
  39.     var iw = $(sel).width();
  40.     //var nh = $("#preimage").height();
  41.     //var ow = $("#image").width();
  42.     //var oh = $("#image").height();
  43.     var ww = $(window).width();
  44.     $(sel).css('left', (ww - iw) / 2);
  45. }
  46.  
  47. $(window).resize(function () {
  48.     centerObj("#preimage");
  49.     centerObj("#image");
  50. });
  51.  
  52. currentimage = 0;
  53.  
  54. $(window).load(function () {
  55.     $("#image").attr('src', images[currentimage]);
  56.     centerObj("#image");
  57. });
  58. </script>
  59. <style>
  60. #preimage {
  61.     display: none;
  62. }
  63.  
  64. #preimage, #image {
  65.     position: absolute;
  66.     top: 3em;
  67. }
  68. </style>
  69. </head>
  70. <body>
  71.  
  72. <a href="javascript:previous()">&lt;</a> - <a href="javascript:next()">&gt;</a>
  73.  
  74. <div id="images">
  75. <img id="preimage" />
  76. <img id="image" />
  77. </div>
  78.  
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement