index.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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
  74. // track of which image you are showing
  75. var counter = 1;
  76. // virtually click on the current
  77. // image to load it into the big image
  78. $("#image" + counter).click();
  79. // when you click on the backwards
  80. // button select the previous image
  81. $("#backward").click(function () {
  82. // go back one in the counter
  83. counter = counter - 1;
  84. // if we are below 1 (the first
  85. // image) loop round to 4 (the
  86. // last image)
  87. if (counter < 1) {
  88. counter = 4;
  89. }
  90. // virtually click on the current
  91. // image to load it into the big image
  92. $("#image" + counter).click();
  93. });
  94. // when you click on the backwards
  95. // button select the next image
  96. $("#forward").click(function () {
  97. // go forward one in the counter
  98. counter = counter + 1;
  99. // if we are above 4 (the last
  100. // image) loop round to 1 (the
  101. // first image)
  102. if (counter > 4) {
  103. counter = 1;
  104. }
  105. // virtually click on the current
  106. // image to load it into the big image
  107. $("#image" + counter).click();
  108. });
  109. // when you click the big image
  110. // toggle pausing. Set paused to
  111. // not paused, i.e. if it is paused
  112. // set it to not paused, if it is
  113. // not paused set it to paused
  114. $("#bigImage").click(function () {
  115. paused = !paused;
  116. });
  117. // set interval makes it move
  118. // forward every 3 second
  119. setInterval(function () {
  120. // first check if it is paused
  121. if (!paused) {
  122. // virtual click the forward
  123. // button
  124. $("#forward").click();
  125. }
  126. ;
  127. }, 3000);
  128. </script>
  129. </body>
  130. </html>