Advertisement
Trankalinos

Slideshow.js

Nov 5th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. // I dunno how this code works exactly, but I'll explain it the best I can.
  2. // the selectObj refers to the individual colours in the drop down menu.
  3. // the following function sets the changeBackground() to refer to the selectObj (or colour for simplicity)
  4. // then, we set a newColor variable to be the selectObj (the drop down menu)
  5. // the .options is the list of selections, and the selectedIndex within the drop down menu are the individual colours.
  6. // finally, the function changes the selection index of 0 (which is the default) to black.
  7. // the document.getElementById('content').style.backgroundColor = newColor; is exactly what it sounds like
  8. // it changes the background colour to black, if we selected black.
  9.  
  10. // try this code out, it'll be easier to understand once you get the gist of it in your html.
  11. // Medhat had a very similar code to this; I am certain he did not use an Array
  12. // that doesn't mean Arrays don't work though.
  13. function changeBackground(selectObj){
  14. newColor = selectObj.options[selectObj.selectedIndex].text;
  15. document.getElementById('content').style.backgroundColor = newColor;
  16. document.getElementById('options').style.backgroundColor = newColor;
  17. }
  18.  
  19.  
  20. // sets up a new array for pictures. These lines of code are self-explanitory
  21. var PicList = new Array();
  22. var PicIndex = 0;
  23. function InstallPics(){
  24. PicList[0] = "images/Arab Spring/arabspring-640x480.jpg";
  25. PicList[1] = "images/Arab Spring/Arabspringisitfallalready_26305.jpg";
  26. PicList[2] = "images/Arab Spring/baby_Egyptian.png";
  27. PicList[3] = "images/Arab Spring/2gvcl.jpg";
  28. PicList[4] = "images/Arab Spring/15249.jpg";
  29. PicList[5] = "images/Arab Spring/EgyptProtestersonTank.jpg";
  30. PicList[6] = "images/Arab Spring/kurdsprotesterssyria.jpg";
  31. PicList[7] = "images/Arab Spring/occupy-wall-street.jpg";
  32. PicList[8] = "images/Arab Spring/rev.jpg";
  33. PicList[9] = "images/Arab Spring/tahrir-square1.jpg";
  34. }
  35.  
  36. // setting up the control buttons
  37. function getNextPic(){
  38. if(PicIndex==9){
  39. // if the picture is the 10th one on the screen, go back to the beginning (where PicIndex is 0)
  40. PicIndex = 0;
  41. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  42. return PicList[PicIndex];
  43.  
  44. }
  45. else{
  46. // otherwise, continue adding 1 to the PicIndex to get the next picture.
  47. PicIndex = (PicIndex + 1);
  48. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  49. return PicList[PicIndex];
  50. }
  51. }
  52. function getPrevPic(){
  53. if(PicIndex==0){
  54. PicIndex = 9;
  55. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  56. return PicList[PicIndex];
  57. }
  58. else{
  59. PicIndex = (PicIndex-1);
  60. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  61. return PicList[PicIndex];
  62. }
  63. }
  64. function getFirstPic(){
  65. PicIndex = 0;
  66. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  67. return PicList[PicIndex];
  68. }
  69. function getLastPic(){
  70. PicIndex = 9;
  71. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  72. return PicList[PicIndex];
  73. }
  74. function getRandomPic(){
  75. PicIndex = Math.floor(1 + Math.random() * 9) ;
  76. document.getElementById('imgName').innerHTML = PicList[PicIndex];
  77. return PicList[PicIndex];
  78. }
  79.  
  80. // Load up the pictures when the website executes this javascript file.
  81. InstallPics();
  82.  
  83. // this is to show the 1 - 10 values on the range slider bar thingy
  84. function showValue(newValue){
  85. document.getElementById('range').innerHTML=newValue;
  86. }
  87.  
  88. // this is the crazy part.
  89. // when we click on the checkmark, we want to hide the controls;
  90. // we should wrap the control buttons inside a div, so we can either show the entire div, or hide it
  91. // instead of hiding each individual button
  92. function showMe(id1, id2) { // This gets executed when the user clicks on the checkbox
  93. var obj1 = document.getElementById(id1);
  94. var obj2 = document.getElementById(id2);
  95. if (obj1.style.visibility=="hidden") { // if it is checked, make it visible, if not, hide it
  96. // also, if one is visible, the other one isn't.
  97. // if the box is unchecked, the buttons are visible; the slider bar is not
  98. obj1.style.visibility = "visible";
  99. obj2.style.visibility = "hidden";
  100. }
  101. else {
  102. // if the box is checked, the buttons disappear; the slider bar becomes visible.
  103. obj1.style.visibility = "hidden";
  104. obj2.style.visibility = "visible";
  105. }
  106. }
  107.  
  108. // I'm still working on the slideshow bit
  109. // Once I figure out the code for it, you guys will be the first to know.
  110. // I recommend everyone to take snippets of my code to see how they work and try to understand what is going on.
  111. // Thats how I did most of what you see above; using other people's code online.
  112. // Good Luck.
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement