Guest User

Untitled

a guest
Apr 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /* Rambutan ;) */
  2.  
  3. &&& &&&& &&& &&&
  4. ¤¤ NOTERINGAR ¤¤
  5. &&& &&&& &&& &&&
  6.  
  7. slideToggle(divens_id, divens_höjd, slide_hastighet);
  8. Glöm inte ha overflow:hidden; på :)
  9.  
  10. &&& &&&& &&&
  11. ¤¤¤ HTML ¤¤¤
  12. &&& &&&& &&&
  13.  
  14. <div style="width:400px;height:20px;text-align:center;background:green;" onclick="slideToggle('my_div',200,3);">Slideopen div</div>
  15.  
  16. <div id="my_div" style="height:0px;width:400px;background:pink;overflow:hidden;">
  17.  
  18. ...content...
  19.  
  20. </div>
  21.  
  22. &&& &&&& &&& &&& &&&&
  23. ¤¤¤¤¤ JAVASCRIPT ¤¤¤¤
  24. &&& &&&& &&&& &&& &&&
  25.  
  26. var open = 0; // öppen eller stängd från början? (funkar typ inte :P)
  27. var height = 0; //ursprunglig höjd
  28.  
  29. function slideToggle(divId,divHeight,divSpeed) {
  30.  
  31. if(open == 0) {
  32.  
  33. open = 1;
  34. slidePlus(divId,divHeight,divSpeed);
  35.  
  36. }
  37.  
  38. else if(open == 1) {
  39.  
  40. open = 0;
  41. slideMinus(divId,divHeight,divSpeed);
  42.  
  43. }
  44.  
  45. }
  46.  
  47. function slidePlus(divId,divHeight,divSpeed) {
  48.  
  49. if(height <= divHeight) {
  50.  
  51. document.getElementById('tjohej_div').style.visibility="visible";
  52. height = height + divSpeed;
  53. document.getElementById('tjohej_div').style.height=height + 'px';
  54. window.setTimeout(function(){slidePlus(divId,divHeight,divSpeed)}, 1);
  55.  
  56. }
  57.  
  58. }
  59.  
  60. function slideMinus(divId,divHeight,divSpeed) {
  61.  
  62. if(height >= 0) {
  63.  
  64. document.getElementById('tjohej_div').style.visibility="visible";
  65. height = height - divSpeed;
  66. document.getElementById('tjohej_div').style.height=height + 'px';
  67. window.setTimeout(function(){slideMinus(divId,divHeight,divSpeed)}, 1);
  68.  
  69. } else {
  70.  
  71. document.getElementById(divId).style.visibility="hidden";
  72.  
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment