scrollButtons.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. function scrollButtons(element, range){
  2. element.parentElement.style.position = "relative"
  3. var buttonTop = document.createElement("div");
  4. var buttonBottom = document.createElement("div");
  5. var buttonLeft = document.createElement("div");
  6. var buttonRight = document.createElement("div");
  7. buttonTop.innerText = "Up";
  8. buttonBottom.innerText = "Down";
  9. buttonLeft.innerText = "Left";
  10. buttonRight.innerText = "Right";
  11. buttonTop.style.position = "absolute";
  12. buttonBottom.style.position = "absolute";
  13. buttonLeft.style.position = "absolute";
  14. buttonRight.style.position = "absolute";
  15. buttonTop.style.top = "20px";
  16. buttonTop.style.left = "180px";
  17. buttonBottom.style.bottom = "30px";
  18. buttonBottom.style.left = "170px";
  19. buttonLeft.style.left = "20px";
  20. buttonLeft.style.top = "190px";
  21. buttonRight.style.right = "1000px";
  22. buttonRight.style.top = "190px";
  23. buttonTop.style.background = "#fff";
  24. buttonBottom.style.background = "#fff";
  25. buttonLeft.style.background = "#fff";
  26. buttonRight.style.background = "#fff";
  27. buttonTop.style.borderRadius = "10px"
  28. buttonBottom.style.borderRadius = "10px"
  29. buttonLeft.style.borderRadius = "10px"
  30. buttonRight.style.borderRadius = "10px"
  31. buttonTop.style.padding = "3px"
  32. buttonBottom.style.padding = "3px"
  33. buttonLeft.style.padding = "3px"
  34. buttonRight.style.padding = "3px"
  35. element.parentElement.appendChild(buttonTop);
  36. element.parentElement.appendChild(buttonBottom);
  37. element.parentElement.appendChild(buttonLeft);
  38. element.parentElement.appendChild(buttonRight);
  39. buttonTop.onclick = function(){
  40. element.scrollTop -= 50;
  41. }
  42. buttonBottom.onclick = function(){
  43. element.scrollTop += 50;
  44. }
  45. buttonLeft.onclick = function(){
  46. element.scrollLeft -= 50;
  47. }
  48. buttonRight.onclick = function(){
  49. element.scrollLeft += 50;
  50. }
  51. }
  52. var element = document.getElementById('someId');
  53. scrollButtons(element, 50);