slideshow.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var numSlides = 0;
  2. var currentSlide = 0;
  3. $(document).ready(function() {
  4. $(document).keyup(handleKeys);
  5. numSlides = $("div.slide").css("display", "none").click(nextSlide).each(function (i) {
  6. $(this).attr("id", "slide_" + i);
  7. }).size();
  8. showSlide();
  9. });
  10. function handleKeys(e) {
  11. var keyID = (window.event) ? event.keyCode : e.keyCode;
  12. switch(keyID) {
  13. case 32:
  14. nextSlide();
  15. break;
  16. case 37:
  17. prevSlide();
  18. break;
  19. case 38:
  20. setSlide(0);
  21. break;
  22. case 39:
  23. nextSlide();
  24. break;
  25. case 40:
  26. lastSlide();
  27. break;
  28. }
  29. }
  30. function showSlide() {
  31. $("div.slide").css("display", "none");
  32. $("#slide_" + currentSlide).css("display", "inline");
  33. }
  34. function setSlide(number) {
  35. currentSlide = number;
  36. showSlide();
  37. }
  38. function nextSlide() {
  39. currentSlide++;
  40. if (currentSlide >= numSlides) {
  41. currentSlide = 0;
  42. }
  43. showSlide();
  44. }
  45. function prevSlide() {
  46. currentSlide--;
  47. if (currentSlide < 0) {
  48. currentSlide = 0;
  49. }
  50. showSlide();
  51. }
  52. function lastSlide() {
  53. currentSlide = (numSlides - 1);
  54. showSlide();
  55. }