wuiyang

Untitled

Apr 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. #test {
  6. display: inline-flex;
  7. flex-wrap: wrap;
  8. }
  9. .t {
  10. width: 200px;
  11. height: 200px;
  12. background-color: #ccc;
  13. margin: 5px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <span onclick='updatelist(-1)'>Left</span>
  19. <div id='test'>
  20. <div class='t'>1</div>
  21. <div class='t'>2</div>
  22. <div class='t'>3</div>
  23. <div class='t'>4</div>
  24. <div class='t'>5</div>
  25. <div class='t'>6</div>
  26. <div class='t'>7</div>
  27. <div class='t'>8</div>
  28. <div class='t'>9</div>
  29. <div class='t'>10</div>
  30. </div>
  31. <span onclick='updatelist(1)'>Right</span>
  32. <script>
  33. var list = document.getElementById("test");
  34. var currentindex = 0;
  35. var totaldisplay = 4;
  36. var totalimages = list.children.length;
  37. for(var i=0;i<totaldisplay-1;i++){
  38. list.insertAdjacentHTML('beforeend', list.children[i].outerHTML);
  39. }
  40. for(var i=totaldisplay; i<totalimages+totaldisplay; i++){
  41. list.children[i].style.display = 'none';
  42. }
  43. function updatelist(val){
  44. var lastindex = currentindex;
  45. currentindex += val;
  46. if(currentindex < 0){
  47. currentindex = totalimages-1;
  48. for(var i=0; i<totaldisplay; i++){
  49. list.children[i].style.display = 'none';
  50. list.children[totalimages+totaldisplay-2-i].style.display = 'block';
  51. }
  52. }else if(currentindex > totalimages-1){
  53. currentindex = 0;
  54. for(var i=0; i<totaldisplay; i++){
  55. list.children[i].style.display = 'block';
  56. list.children[totalimages+totaldisplay-2-i].style.display = 'none';
  57. }
  58. }else{
  59. if(val == 1){
  60. list.children[lastindex].style.display = 'none';
  61. list.children[lastindex+totaldisplay].style.display = 'block';
  62. }
  63. if(val == -1){
  64. list.children[lastindex+totaldisplay-1].style.display = 'none';
  65. list.children[lastindex-1].style.display = 'block';
  66. }
  67. }
  68. }
  69. </script>
  70. </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment