gallery.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <html>
  2. <head>
  3. <title>Image Gallery</title>
  4. <!-- import bootstrap -->
  5. <link rel="stylesheet" type="text/css" href="/css/bootstrap.css" />
  6. <!-- import our own stylesheet -->
  7. <link rel="stylesheet" type="text/css" href="/css/styles.css" />
  8. <!-- import jQuery -->
  9. <script type="text/ecmascript" src="/lib/jquery-2.2.1.js"></script>
  10. </head>
  11. <body>
  12. <!-- some header info (from Matthew's code) -->
  13. <a href="index.html">Home</a>
  14. &nbsp;
  15. <a href="aboutme.html">About me</a>
  16. &nbsp;
  17. <a href="contact.html">Contact me</a>
  18. <hr />
  19. <div class="container">
  20. <h1>Image Gallery</h1>
  21. <!--
  22. These are the thumbnail images.
  23. They pretty much the same as the
  24. last example from the previous
  25. module, except I have added an
  26. id to each image which includes
  27. the number of that image.
  28. -->
  29. <div class="row">
  30. <div class="col-md-3">
  31. <img id="image1" class="crop-img" src="/images/img_1.jpg" alt="graffittied building"/>
  32. </div>
  33. <div class="col-md-3">
  34. <img id="image2" class="crop-img" src="/images/img_3.jpg" alt="display of cheese"/>
  35. </div>
  36. <div class="col-md-3">
  37. <img id="image3" class="crop-img" src="/images/img_4.jpg" alt="synethesizer workshop"/>
  38. </div>
  39. <div class="col-md-3">
  40. <img id="image4" class="crop-img" src="/images/img_5.jpg" alt="City night"/>
  41. </div>
  42. </div>
  43. <!--
  44. this is the large image which is
  45. on a row of its own.
  46. The code is similar to the last example
  47. of the previous module, but I have
  48. added a backwards and forwards button
  49. -->
  50. <div class="row">
  51. <div class="col-md-1">
  52. <button id="backward">&lt;</button>
  53. </div>
  54. <div class="col-md-10">
  55. <img id="bigImage" class="large-img" src="/images/img_1.jpg" alt="graffittied building"/>
  56. </div>
  57. <div class="col-md-1">
  58. <button id="forward">&gt;</button>
  59. </div>
  60. </div>
  61. </div>
  62. <script>
  63. // Whether the slideshow is paused or not.
  64. var paused = false;
  65. // when we click on the thumbnail
  66. // we set the src attribute of the
  67. // big image to be the same as the
  68. // src of the image we have clicked on.
  69. $(".crop-img").click(function(){
  70. $("#bigImage").attr('src',
  71. $(this).attr('src'));
  72. });
  73. // The counter variable that keeps track of which image you are showing.
  74. var counter = 1;
  75. // Virtually click on the current image to load it into the big image.
  76. $("#image" + counter).click();
  77. // When you click on the backwards button select the previous image
  78. $("#backward").click(function () {
  79. // Go back one in the counter.
  80. counter--;
  81. // If we are below 1 (the first image) loop round to 4 (the last image).
  82. if (counter < 1) {
  83. counter = 4;
  84. }
  85. // Virtually click on the current image to load it into the big image.
  86. $("#image" + counter).click();
  87. });
  88. // When you click on the backwards button select the next image.
  89. $("#forward").click(function () {
  90. // Go forward one in the counter.
  91. counter++;
  92. // If we are above 4 (the last image) loop round to 1 (the first image).
  93. if (counter > 4) {
  94. counter = 1;
  95. }
  96. // Virtually click on the current image to load it into the big image.
  97. $("#image" + counter).click();
  98. });
  99. // When you click the big image toggle pausing. Set paused to not paused,
  100. // i.e. if it is paused set it to not paused, if it is not paused set it
  101. // to paused.
  102. $("#bigImage").click(function () {
  103. paused = !paused;
  104. });
  105. // Set interval makes it move forward every 3 second.
  106. setInterval(function () {
  107. // First check if it is paused.
  108. if (!paused) {
  109. // Virtual click the forward button.
  110. $("#forward").click();
  111. }
  112. }, 3000);
  113. </script>
  114. </body>
  115. </html>