使用Gridster. js Plugin实现图片拖拽功能cid1049 -网页前端设计


html and css

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <style>
  7. body {
  8. background: #34495e;
  9. overflow: hidden;
  10. }
  11. li {
  12. list-style: none;
  13. cursor: pointer;
  14. background-size: cover;
  15. }
  16. li:nth-child(1){
  17. background-image: url(one.jpg);
  18. }
  19. li:nth-child(2){
  20. background-image: url(006.jpg);
  21. }
  22. li:nth-child(3){
  23. background-image: url(two.jpg);
  24. }
  25. li:nth-child(4){
  26. background-image: url(one.jpg);
  27. background-size: cover;
  28. background-position: center;
  29. }
  30. li:nth-child(5){
  31. background-image: url(3.jpg);
  32. background-size: cover;
  33. background-position: center;
  34. }
  35. li:nth-child(6){
  36. background-image: url(001.jpg);
  37. background-size: cover;
  38. background-position: center;
  39. }
  40. li:nth-child(7){
  41. background-image: url(6.jpg);
  42. background-size: cover;
  43. background-position: center;
  44. }
  45. li:nth-child(8){
  46. background-image: url(002.jpg);
  47. background-size: cover;
  48. background-position: center;
  49. }
  50. li:nth-child(9){
  51. background-image: url(008.jpg);
  52. background-size: cover;
  53. background-position: center;
  54. }
  55. li:nth-child(10){
  56. background-image: url(003.jpg);
  57. background-size: cover;
  58. background-position: center;
  59. }
  60. li:nth-child(11){
  61. background-image: url(004.jpg);
  62. background-size: cover;
  63. background-position: center;
  64. }
  65. li:nth-child(12){
  66. background-image: url(006.jpg);
  67. background-size: cover;
  68. background-position: center;
  69. }
  70. .gridster{
  71. position:relative
  72. }
  73. .gridster>*
  74. {
  75. margin:0 auto;
  76. transition:height .4s,width .4s}
  77. .gridster .gs-w{
  78. z-index:2;
  79. position:absolute
  80. }
  81. .ready .gs-w:not(.preview-holder)
  82. {
  83. transition:opacity .3s,left .3s,top .3s
  84. }
  85. .ready .gs-w:not(.preview-holder),
  86. .ready .resize-preview-holder
  87. {
  88. transition:opacity .3s,left .3s,top .3s,width .3s,height .3s
  89. }
  90. .gridster .preview-holder
  91. {
  92. z-index:1;
  93. position:absolute;
  94. background-color:#fff;
  95. border-color:#fff;
  96. opacity:.3
  97. }
  98. .gridster .player-revert
  99. {
  100. z-index:10!important;
  101. transition:left .3s,top .3s!important
  102. }
  103. .gridster .dragging,.gridster .resizing{
  104. z-index:10!important;
  105. transition:all 0s!important;
  106. }
  107. .gs-resize-handle{position:absolute;z-index:1}
  108. .gs-resize-handle-both{
  109. width:20px;
  110. height:20px;
  111. bottom:-8px;
  112. right:-8px;
  113. }
  114. .gs-resize-handle-x{
  115. top:0;
  116. bottom:13px;
  117. right:-5px;
  118. width:10px;
  119. cursor:e-resize}
  120. .gs-resize-handle-y{
  121. left:0;
  122. right:13px;
  123. bottom:-5px;
  124. height:10px;
  125. cursor:s-resize}
  126. .gs-w:hover .gs-resize-handle,
  127. .resizing
  128. .gs-resize-handle{opacity:1}
  129. .gs-resize-handle,
  130. .gs-w.dragging
  131. .gs-resize-handle
  132. {opacity:0}
  133. .gs-resize-disabled
  134. .gs-resize-handle{display:none!important}
  135. [data-max-sizex="1"]
  136. .gs-resize-handle-x,[data-max-sizey="1"]
  137. .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"]
  138. .gs-resize-handle{display:none!important}
  139. </style>
  140. </head>
  141. <body>
  142. <br><br><br><br><br><br><br><br>
  143. <div class="gridster">
  144. <ul>
  145. <li data-row="1" data-col="1" data-sizex="1" data-sizey="1"></li>
  146. <li data-row="2" data-col="1" data-sizex="1" data-sizey="1"></li>
  147. <li data-row="3" data-col="1" data-sizex="1" data-sizey="1"></li>
  148. <li data-row="1" data-col="2" data-sizex="2" data-sizey="1"></li>
  149. <li data-row="2" data-col="2" data-sizex="2" data-sizey="2"></li>
  150. <li data-row="1" data-col="4" data-sizex="1" data-sizey="1"></li>
  151. <li data-row="2" data-col="4" data-sizex="2" data-sizey="1"></li>
  152. <li data-row="3" data-col="4" data-sizex="1" data-sizey="1"></li>
  153. <li data-row="1" data-col="5" data-sizex="1" data-sizey="1"></li>
  154. <li data-row="3" data-col="5" data-sizex="1" data-sizey="1"></li>
  155. <li data-row="1" data-col="6" data-sizex="1" data-sizey="1"></li>
  156. <li data-row="2" data-col="6" data-sizex="1" data-sizey="2"></li>
  157. </ul>
  158. </div>
  159. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  160. <script src="jquery.gridster.min.js"></script>
  161. <script>
  162. $(function(){ //DOM Ready
  163. $(".gridster ul").gridster({
  164. widget_margins: [10, 10],
  165. widget_base_dimensions: [140, 140],
  166. min_cols: 6,
  167. resize: {
  168. enabled: true,
  169. max_size: [2, 2],
  170. min_size: [1, 1]
  171. }
  172. });
  173. });
  174. </script>
  175. </body>
  176. </html>
  <!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <style>
     
     body {
         background: #34495e;
         overflow: hidden;
}
li {
  
  list-style: none;
  cursor: pointer;
    background-size: cover;
}
         li:nth-child(1){
             background-image: url(one.jpg);
              
         }
         
         li:nth-child(2){
             background-image: url(006.jpg);
         }
         li:nth-child(3){
             background-image: url(two.jpg);
         }
         
         li:nth-child(4){
             background-image: url(one.jpg);
             background-size: cover;
             background-position: center;
            
         }
          li:nth-child(5){
             background-image: url(3.jpg);
             background-size: cover;
             background-position: center;
         }
         
          li:nth-child(6){
             background-image: url(001.jpg);
             background-size: cover;
             background-position: center;
         }
         
          li:nth-child(7){
             background-image: url(6.jpg);
             background-size: cover;
             background-position: center;
         }
           li:nth-child(8){
             background-image: url(002.jpg);
             background-size: cover;
             background-position: center;
         }
           li:nth-child(9){
             background-image: url(008.jpg);
             background-size: cover;
             background-position: center;
         }
            li:nth-child(10){
             background-image: url(003.jpg);
             background-size: cover;
             background-position: center;
         }
         
         
           li:nth-child(11){
             background-image: url(004.jpg);
             background-size: cover;
             background-position: center;
         }
         
           li:nth-child(12){
             background-image: url(006.jpg);
             background-size: cover;
             background-position: center;
         }
         
         
         
         
         
         
         
 
.gridster{
    position:relative
    }
.gridster>*
         {
         margin:0 auto;      
         transition:height .4s,width .4s}
         
         .gridster .gs-w{
             z-index:2;
             position:absolute
         }
         
         
         
         
         
             .ready .gs-w:not(.preview-holder)
             {
                 transition:opacity .3s,left .3s,top .3s
         
              }
         
         
         
         
               .ready .gs-w:not(.preview-holder),
               .ready .resize-preview-holder
               {                   
                   transition:opacity .3s,left .3s,top .3s,width .3s,height .3s
         
              }
          
                .gridster .preview-holder  
                   {
                       z-index:1;
                       position:absolute;
                       background-color:#fff;
                       border-color:#fff;
                       opacity:.3
         
                   }
         
         
         .gridster .player-revert
         {
             z-index:10!important;             
             transition:left .3s,top .3s!important
         }
         
          .gridster .dragging,.gridster .resizing{
              z-index:10!important;                 
              transition:all 0s!important;
         
         }
           .gs-resize-handle{position:absolute;z-index:1}
         
         .gs-resize-handle-both{
             width:20px;
             height:20px;
             bottom:-8px;
             right:-8px;
            }
         
         .gs-resize-handle-x{
          top:0;
          bottom:13px;
          right:-5px;
          width:10px;
          cursor:e-resize}
         
         .gs-resize-handle-y{
             left:0;
             right:13px;
             bottom:-5px;
             height:10px;
             cursor:s-resize}
         
         .gs-w:hover .gs-resize-handle,
         .resizing 
         .gs-resize-handle{opacity:1}
         .gs-resize-handle,
         .gs-w.dragging 
         .gs-resize-handle
         {opacity:0}
         
         
         
         .gs-resize-disabled 
         .gs-resize-handle{display:none!important}
         [data-max-sizex="1"] 
         
         .gs-resize-handle-x,[data-max-sizey="1"] 
         
         .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"] 
         
         .gs-resize-handle{display:none!important}

 </style>
 </head>
 <body>
    <br><br><br><br><br><br><br><br>
     <div class="gridster">
    <ul>
        <li data-row="1" data-col="1" data-sizex="1" data-sizey="1"></li>
        <li data-row="2" data-col="1" data-sizex="1" data-sizey="1"></li>
        <li data-row="3" data-col="1" data-sizex="1" data-sizey="1"></li>
 
        <li data-row="1" data-col="2" data-sizex="2" data-sizey="1"></li>
        <li data-row="2" data-col="2" data-sizex="2" data-sizey="2"></li>
 
        <li data-row="1" data-col="4" data-sizex="1" data-sizey="1"></li>
        <li data-row="2" data-col="4" data-sizex="2" data-sizey="1"></li>
        <li data-row="3" data-col="4" data-sizex="1" data-sizey="1"></li>
 
        <li data-row="1" data-col="5" data-sizex="1" data-sizey="1"></li>
        <li data-row="3" data-col="5" data-sizex="1" data-sizey="1"></li>
 
        <li data-row="1" data-col="6" data-sizex="1" data-sizey="1"></li>
        <li data-row="2" data-col="6" data-sizex="1" data-sizey="2"></li>
    </ul>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="jquery.gridster.min.js"></script>
<script>
     $(function(){ //DOM Ready
 
    $(".gridster ul").gridster({
        widget_margins: [10, 10],
        widget_base_dimensions: [140, 140],
        min_cols: 6,
        resize: {
            enabled: true,
            max_size: [2, 2],
            min_size: [1, 1]
          }
    });
 
});
</script>
 </body>
 </html>

在线演示? 让链接同时具备两种打开方式

获取源码: Gridst9er.js
下载数:79人次, 文件大小: 665.8 KB, 上传日期: 2020年-11 月-25日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

2,377 人查阅

类似文章