tricky-drag.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>tricky drag</title>
  7. <link rel="stylesheet" href="../css/flickity.css" />
  8. <style>
  9. .carousel {
  10. background: #EEE;
  11. margin-bottom: 40px;
  12. }
  13. .carousel-cell {
  14. height: 200px;
  15. width: 25%;
  16. margin: 0 10px;
  17. background: #6C6;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. border-radius: 8px;
  22. }
  23. .carousel-cell b {
  24. display: block;
  25. font-size: 80px;
  26. color: white;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <h1>tricky drag</h1>
  32. <div class="carousel carousel--non-drag">
  33. <div class="carousel-cell"><b>1</b></div>
  34. <div class="carousel-cell"><b>2</b></div>
  35. <div class="carousel-cell"><b>3</b></div>
  36. <div class="carousel-cell"><b>4</b></div>
  37. <div class="carousel-cell"><b>5</b></div>
  38. <div class="carousel-cell"><b>6</b></div>
  39. <div class="carousel-cell"><b>7</b></div>
  40. </div>
  41. <div class="carousel carousel--single-cell">
  42. <div class="carousel-cell"><b>1</b></div>
  43. </div>
  44. <div class="carousel carousel--group">
  45. <div class="carousel-cell"><b>1</b></div>
  46. <div class="carousel-cell"><b>2</b></div>
  47. </div>
  48. <p><button class="add-group-cell-button">Add cell</button></p>
  49. <script src="../bower_components/get-size/get-size.js"></script>
  50. <script src="../bower_components/desandro-matches-selector/matches-selector.js"></script>
  51. <script src="../bower_components/ev-emitter/ev-emitter.js"></script>
  52. <script src="../bower_components/unipointer/unipointer.js"></script>
  53. <script src="../bower_components/unidragger/unidragger.js"></script>
  54. <script src="../bower_components/fizzy-ui-utils/utils.js"></script>
  55. <script src="../js/cell.js"></script>
  56. <script src="../js/slide.js"></script>
  57. <script src="../js/animate.js"></script>
  58. <script src="../js/flickity.js"></script>
  59. <script src="../js/drag.js"></script>
  60. <script src="../js/prev-next-button.js"></script>
  61. <script src="../js/page-dots.js"></script>
  62. <script src="../js/player.js"></script>
  63. <script src="../js/add-remove-cell.js"></script>
  64. <script>
  65. var nonDragFlkty = new Flickity( '.carousel--non-drag', {
  66. draggable: false,
  67. });
  68. function onStaticClick( event, pointer, cellElem, cellIndex ) {
  69. console.log('staticClick', this.element.className, cellIndex );
  70. }
  71. nonDragFlkty.on( 'staticClick', onStaticClick );
  72. var singleCellFlkty = new Flickity('.carousel--single-cell');
  73. singleCellFlkty.on( 'staticClick', onStaticClick );
  74. var groupCarousel = document.querySelector('.carousel--group');
  75. var groupFlkty = new Flickity( groupCarousel, {
  76. groupCells: true,
  77. });
  78. groupFlkty.on( 'staticClick', function( event, pointer, cellElem, cellIndex ) {
  79. if ( cellElem ) {
  80. groupFlkty.remove( cellElem );
  81. }
  82. });
  83. function makeGroupCell() {
  84. var cell = document.createElement('div');
  85. cell.className = 'carousel-cell';
  86. var b = document.createElement('b');
  87. b.textContent = groupFlkty.cells.length + 1;
  88. cell.appendChild( b );
  89. return cell;
  90. }
  91. document.querySelector('.add-group-cell-button').onclick = function() {
  92. groupFlkty.append( makeGroupCell() );
  93. };
  94. </script>
  95. </body>
  96. </html>