Advertisement
gitlez

EasySlideshow

Jun 7th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. <?php
  2. /*
  3. Instructions:
  4. Place script in the same directory as the images.
  5. Navigate, in a browser, to this script.
  6.  
  7. */
  8. $imgFiles = Array();
  9. $dh = opendir('.');
  10. while($file = readdir($dh)){
  11. $ext = strtolower(pathinfo($file,PATHINFO_EXTENSION));
  12. $imgExts = Array('jpg','gif','png');
  13. if(in_array($ext,$imgExts)){
  14. $imgFiles[] = $file;
  15. }
  16. }
  17.  
  18. ?>
  19. <html>
  20. <head>
  21. <title>Easy Slideshow</title>
  22. <script type="text/javascript" language="Javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
  23. <script type="text/javascript" language="Javascript">
  24.  
  25. // Following speeds are in milliseconds ( 1 second = 1000 miliseconds);
  26. var aniSpeed = 500;
  27.  
  28. // No Need to change the following variables
  29. var winW = 0;
  30. var winH = 0;
  31. var numOfImages = 0;
  32. var origWH = new Array();
  33. var index = 1;
  34. var curImg;
  35. var tInterval;
  36. var navButtonPadding;
  37.  
  38. function screenDimensions(){
  39. winW = $(window).width();
  40. winH = $(window).height();
  41. }
  42. function imgSizer(){
  43. // Image Scalling To Window
  44. var img = $('#easySlideshow_G12 img:nth-child(' + index + ')');
  45. var origW = origWH[index-1][0];
  46. var origH = origWH[index-1][1];
  47. if(origW > winW || origH > winH){
  48. var hR = origW / winW;
  49. var vR = origH / winH;
  50. var ratio = ((hR > vR)? hR : vR);
  51. $(img).width(Math.round(origW / ratio));
  52. $(img).height(Math.round(origH / ratio));
  53. }else{
  54. $(img).width(origW);
  55. $(img).height(origH);
  56. }
  57. // Center the image in the window
  58. $(img).css({left: ((winW - $(img).width())/2), top: ((winH - $(img).height())/2)});
  59. // Align the Navigation Buttons
  60. var posLeft,posRight;
  61. if(($(img).width() + $('#navLeft').width() + $('#navRight').width()) < winW){
  62. var leftNewLeft = (parseInt($(img).css('left')) - $('#navLeft').width() - navButtonPadding);
  63. var rightNewLeft = (parseInt($(img).css('left')) + $(img).width());
  64. }else{
  65. var leftNewLeft = 0;
  66. var rightNewLeft = winW - ($('#navRight').width() + navButtonPadding);
  67. }
  68. var middle = (winH/2) - ($('#navRight').height() / 2);
  69. $('#navLeft').css({top: middle}).animate({left: leftNewLeft}, (aniSpeed/2));
  70. $('#navRight').css({top: middle}).animate({left: rightNewLeft}, (aniSpeed/2));
  71. }
  72. function slideshow(){
  73. if(index == numOfImages){
  74. index = 1;
  75. }else if(index < 1){
  76. index = (numOfImages - 1);
  77. }
  78. if(curImg != undefined && curImg != null){
  79. $(curImg).fadeOut(aniSpeed);
  80. }
  81. $('#easySlideshow_G12 img:nth-child(' + index + ')').fadeIn(aniSpeed+1, function(){
  82. curImg = this;
  83. });
  84. imgSizer();
  85. }
  86. $(function(){
  87. screenDimensions();
  88. numOfImages = $('#easySlideshow_G12 img').length;
  89. $('#easySlideshow_G12 img').each(function(){
  90. origWH.push(new Array($(this).width(), $(this).height()));
  91. $(this).css({position: 'absolute', left: 0, top: 0, display: 'none', cursor: 'pointer'});
  92. }).click(function(){
  93. window.open($(this).attr('src'));
  94. });
  95. $('#easySlideshow_G12 img:last').load(function(){
  96. slideshow();
  97. });
  98. // Varible Filling (Do not alter unless you know)
  99. navButtonPadding = parseInt($('#navLeft').css('border-left-width')) + parseInt($('#navLeft').css('border-right-width'));
  100. $('#navLeft').click(function(){
  101. index--;
  102. slideshow();
  103. });
  104. $('#navRight').click(function(){
  105. index++;
  106. slideshow();
  107. });
  108. // Window resizing listener
  109. $(window).resize(screenDimensions);
  110. });
  111. </script>
  112. <style type="text/css">
  113. .navButton {
  114. position: absolute;
  115. width: 25px;
  116. height: 25px;
  117. cursor: pointer;
  118. background-color: #666;
  119. border-color: #333;
  120. border-style: double;
  121. border-radius: 8px;
  122. }
  123. .navButton span {
  124. color: #FFF;
  125. font-size: 20px;
  126. font-weight: bold;
  127. text-align: center;
  128. position: absolute;
  129. left: 1px;
  130. vertical-align: middle;
  131. font-family: Impact;
  132. }
  133. </style>
  134. </head>
  135. <body>
  136. <div id="easySlideshow_G12">
  137. <?php
  138. $c = count($imgFiles);
  139. for($i=0;$i<$c;++$i){
  140. $imgInfo = getimagesize($imgFiles[$i]);
  141. echo '<img src="' . $imgFiles[$i] . '" ' . $imgInfo[3] . ' />' . PHP_EOL;
  142. }
  143. ?>
  144. </div>
  145. <div class="navButton" id="navLeft"><span><<</span></div>
  146. <div class="navButton" id="navRight"><span>>></span></div>
  147. </body>
  148. </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement