博客列表 >微信小程序自定义裁剪图片并压缩

微信小程序自定义裁剪图片并压缩

搁浅
搁浅原创
2022年10月12日 10:49:451118浏览

wxml

  1. <view class="wx-content-info" wx:if="{{imageSrc}}">
  2. <view wx:if="{{isShowImg}}" class="wx-corpper" style="width:{{cropperInitW}}rpx;height:{{cropperInitH}}rpx;background:#000">
  3. <view class="wx-corpper-content" style="width:{{cropperW}}rpx;height:{{cropperH}}rpx;left:{{cropperL}}rpx;top:{{cropperT}}rpx">
  4. <image src="{{imageSrc}}" style="width:{{cropperW}}rpx;height:{{cropperH}}rpx"></image>
  5. <view class="wx-corpper-crop-box" bindtouchstart="contentStartMove" bindtouchmove="contentMoveing" style="width:{{cutW}}rpx;height:{{cutH}}rpx;left:{{cutL}}rpx;top:{{cutT}}rpx">
  6. <view class="wx-cropper-view-box">
  7. <view class="wx-cropper-dashed-h"></view>
  8. <view class="wx-cropper-dashed-v"></view>
  9. <view class="wx-cropper-line-t" data-drag="top" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  10. <view class="wx-cropper-line-r" data-drag="right" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  11. <view class="wx-cropper-line-b" data-drag="bottom" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  12. <view class="wx-cropper-line-l" data-drag="left" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  13. <view class="wx-cropper-point point-t" data-drag="top" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  14. <view class="wx-cropper-point point-tr" data-drag="topTight"></view>
  15. <view class="wx-cropper-point point-r" data-drag="right" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  16. <view class="wx-cropper-point point-rb" data-drag="rightBottom" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  17. <view class="wx-cropper-point point-b" data-drag="bottom" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  18. <view class="wx-cropper-point point-bl" data-drag="bottomLeft"></view>
  19. <view class="wx-cropper-point point-l" data-drag="left" catchtouchstart="dragStart" catchtouchmove="dragMove"></view>
  20. <view class="wx-cropper-point point-lt" data-drag="leftTop"></view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <canvas canvas-id="myCanvas" style="position:absolute;border: 1px solid red; width:{{imageW}}rpx;height:{{imageH}}rpx;top:-9999px;left:-9999px;"></canvas>
  26. <view style="text-align: center;"><image style="width: 192rpx;height: 192rpx;border-radius: 500rpx !important;overflow: hidden; margin-top: 30rpx;margin-bottom: 30rpx;" src="{{returnImage}}"></image></view>
  27. <view style="display: flex;">
  28. <button type="primary" bindtap="getImageInfo">头像预览</button>
  29. <button type="primary" bindtap="upload" loading="{{isdisabled}}" disabled="{{isdisabled}}">上传头像</button>
  30. </view>
  31. </view>

js

  1. const app = getApp();
  2. // 手机的宽度
  3. var windowWRPX = 750
  4. // 拖动时候的 pageX
  5. var pageX = 0
  6. // 拖动时候的 pageY
  7. var pageY = 0
  8. var pixelRatio = wx.getSystemInfoSync().pixelRatio
  9. // 调整大小时候的 pageX
  10. var sizeConfPageX = 0
  11. // 调整大小时候的 pageY
  12. var sizeConfPageY = 0
  13. var initDragCutW = 0
  14. var initDragCutL = 0
  15. var initDragCutH = 0
  16. var initDragCutT = 0
  17. // 移动时 手势位移与 实际元素位移的比
  18. var dragScaleP = 2
  19. Page({
  20. /**
  21. * 页面的初始数据
  22. */
  23. data: {
  24. topLabel: '头像上传', //顶部栏input
  25. isIphoneX: app.globalStore.globalData.isIphoneX, //是否Iphonx
  26. windowHeight: app.globalStore.globalData.windowHeight,
  27. windowWidth: app.globalStore.globalData.windowWidth,
  28. triggered: false, //模块是否刷新中
  29. isdisabled: false, //是否提交
  30. showmodel: false, //是否编辑模式
  31. imageSrc: '',
  32. returnImage: '',
  33. isShowImg: false,
  34. // 初始化的宽高
  35. cropperInitW: windowWRPX,
  36. cropperInitH: windowWRPX,
  37. // 动态的宽高
  38. cropperW: windowWRPX,
  39. cropperH: windowWRPX,
  40. // 动态的left top值
  41. cropperL: 0,
  42. cropperT: 0,
  43. // 图片缩放值
  44. scaleP: 0,
  45. imageW: 0,
  46. imageH: 0,
  47. // 裁剪框 宽高
  48. cutW: 0,
  49. cutH: 0,
  50. cutL: 0,
  51. cutT: 0,
  52. },
  53. upload(e) { //头像上传
  54. wx.showLoading({
  55. title: '头像上传中...',
  56. })
  57. this.setData({isdisabled:true})
  58. const userinfo = wx.getStorageSync('userinfo')
  59. let encryptor = new Encrypt.JSEncrypt()
  60. encryptor.setPublicKey(publicKey);
  61. let requestkey = encryptor.encrypt(userinfo.YHBH + ',' + userinfo.OPENID + ',' + userinfo.BH + ',' + new Date().getTime()) // 加密
  62. // 将图片写入画布
  63. const ctx = wx.createCanvasContext('myCanvas')
  64. ctx.drawImage(this.data.imageSrc)
  65. ctx.draw(true, () => {
  66. // 获取画布要裁剪的位置和宽度 均为百分比 * 画布中图片的宽度 保证了在微信小程序中裁剪的图片模糊 位置不对的问题
  67. let canvasW = (this.data.cutW / this.data.cropperW) * (this.data.imageW / pixelRatio)
  68. let canvasH = (this.data.cutH / this.data.cropperH) * (this.data.imageH / pixelRatio)
  69. let canvasL = (this.data.cutL / this.data.cropperW) * (this.data.imageW / pixelRatio)
  70. let canvasT = (this.data.cutT / this.data.cropperH) * (this.data.imageH / pixelRatio)
  71. setTimeout(() => {
  72. wx.canvasToTempFilePath({
  73. x: canvasL,
  74. y: canvasT,
  75. width: canvasW,
  76. height: canvasH,
  77. destWidth: canvasW * 0.35,//设置压缩百分比,如果写100就是分辨率
  78. destHeight: canvasH * 0.35,//设置压缩百分比,如果写100就是分辨率
  79. canvasId: 'myCanvas',
  80. fileType: 'jpg',
  81. success: res => {
  82. wx.uploadFile({
  83. url: App.uploads + '/weixin/upload/img/upload/cover',
  84. filePath: res.tempFilePath,
  85. name: 'file',
  86. header: {
  87. token: requestkey
  88. },
  89. formData: {
  90. BH: wx.getStorageSync('userinfo').BH
  91. },
  92. success:res=>{
  93. res.data = JSON.parse(res.data)
  94. let pages = getCurrentPages();
  95. let previousPage = pages[pages.length - 2]; //上一个页面
  96. previousPage.setData({
  97. avatarUrl: res.data.data.filePath
  98. })
  99. const userinfo = wx.getStorageSync('userinfo')
  100. userinfo.TX = res.data.data.filePath
  101. wx.setStorageSync('userinfo', userinfo)
  102. wx.hideLoading()
  103. wx.showToast({
  104. title: '上传成功',
  105. icon: "succes",
  106. duration: 1500
  107. })
  108. this.setData({isdisabled:false})
  109. },
  110. fail:res=>{
  111. this.setData({isdisabled:false})
  112. wx.hideLoading()
  113. wx.showToast({
  114. title: '上传失败',
  115. icon: "error",
  116. duration: 1500
  117. })
  118. }
  119. })
  120. }
  121. })
  122. }, 500);
  123. })
  124. },
  125. // 拖动时候触发的touchStart事件
  126. contentStartMove(e) {
  127. pageX = e.touches[0].pageX
  128. pageY = e.touches[0].pageY
  129. },
  130. // 拖动时候触发的touchMove事件
  131. contentMoveing(e) {
  132. // this.data.cutL + (e.touches[0].pageX - pageX)
  133. // console.log(e.touches[0].pageX)
  134. // console.log(e.touches[0].pageX - pageX)
  135. var dragLengthX = (pageX - e.touches[0].pageX) * dragScaleP
  136. var dragLengthY = (pageY - e.touches[0].pageY) * dragScaleP
  137. var minX = Math.max(this.data.cutL - (dragLengthX), 0)
  138. var minY = Math.max(this.data.cutT - (dragLengthY), 0)
  139. var maxX = this.data.cropperW - this.data.cutW
  140. var maxY = this.data.cropperH - this.data.cutH
  141. this.setData({
  142. cutL: Math.min(maxX, minX),
  143. cutT: Math.min(maxY, minY),
  144. })
  145. // console.log(`${maxX} ----- ${minX}`)
  146. pageX = e.touches[0].pageX
  147. pageY = e.touches[0].pageY
  148. },
  149. // 获取图片
  150. getImageInfo() {
  151. wx.showLoading({
  152. title: '图片生成中...',
  153. })
  154. wx.downloadFile({
  155. url: this.data.imageSrc, //仅为示例,并非真实的资源
  156. success: res=>{
  157. // 将图片写入画布
  158. const ctx = wx.createCanvasContext('myCanvas')
  159. ctx.drawImage(res.tempFilePath)
  160. ctx.draw(true, () => {
  161. // 获取画布要裁剪的位置和宽度 均为百分比 * 画布中图片的宽度 保证了在微信小程序中裁剪的图片模糊 位置不对的问题
  162. let canvasW = (this.data.cutW / this.data.cropperW) * (this.data.imageW / pixelRatio)
  163. let canvasH = (this.data.cutH / this.data.cropperH) * (this.data.imageH / pixelRatio)
  164. let canvasL = (this.data.cutL / this.data.cropperW) * (this.data.imageW / pixelRatio)
  165. let canvasT = (this.data.cutT / this.data.cropperH) * (this.data.imageH / pixelRatio)
  166. setTimeout(() => {
  167. wx.canvasToTempFilePath({
  168. x: canvasL,
  169. y: canvasT,
  170. width: canvasW,
  171. height: canvasH,
  172. destWidth: canvasW * 0.35,//设置压缩百分比,如果写100就是分辨率
  173. destHeight: canvasH * 0.35,//设置压缩百分比,如果写100就是分辨率
  174. canvasId: 'myCanvas',
  175. fileType: 'jpg',
  176. success: res=>{
  177. wx.hideLoading()
  178. // wx.getImageInfo({
  179. // src: res.tempFilePath,
  180. // success (res) {
  181. // console.log(res.width)//图片宽
  182. // console.log(res.height)//图片高
  183. // }
  184. // })
  185. // 成功获得地址的地方
  186. wx.previewImage({
  187. current: '', // 当前显示图片的http链接
  188. urls: [res.tempFilePath] // 需要预览的图片http链接列表
  189. })
  190. this.setData({
  191. returnImage:res.tempFilePath
  192. })
  193. }
  194. })
  195. }, 200);
  196. })
  197. }
  198. })
  199. },
  200. // 设置大小的时候触发的touchStart事件
  201. dragStart(e) {
  202. sizeConfPageX = e.touches[0].pageX
  203. sizeConfPageY = e.touches[0].pageY
  204. initDragCutW = this.data.cutW
  205. initDragCutL = this.data.cutL
  206. initDragCutT = this.data.cutT
  207. initDragCutH = this.data.cutH
  208. },
  209. // 设置大小的时候触发的touchMove事件
  210. dragMove(e) {
  211. var dragType = e.target.dataset.drag
  212. switch (dragType) {
  213. case 'right':
  214. var dragLength = (sizeConfPageX - e.touches[0].pageX) * dragScaleP
  215. if (initDragCutW >= dragLength) {
  216. // 如果 移动小于0 说明是在往下啦 放大裁剪的高度 这样一来 图片的高度 最大 等于 图片的top值加 当前图片的高度 否则就说明超出界限
  217. if (dragLength < 0 && this.data.cropperW > initDragCutL + this.data.cutW) {
  218. this.setData({
  219. cutW: initDragCutW - dragLength
  220. })
  221. }
  222. // 如果是移动 大于0 说明在缩小 只需要缩小的距离小于原本裁剪的高度就ok
  223. if (dragLength > 0) {
  224. this.setData({
  225. cutW: initDragCutW - dragLength
  226. })
  227. } else {
  228. return
  229. }
  230. } else {
  231. return
  232. }
  233. break;
  234. case 'left':
  235. var dragLength = (dragLength = sizeConfPageX - e.touches[0].pageX) * dragScaleP
  236. console.log(dragLength)
  237. if (initDragCutW >= dragLength && initDragCutL > dragLength) {
  238. if (dragLength < 0 && Math.abs(dragLength) >= initDragCutW) return
  239. this.setData({
  240. cutL: initDragCutL - dragLength,
  241. cutW: initDragCutW + dragLength
  242. })
  243. } else {
  244. return;
  245. }
  246. break;
  247. case 'top':
  248. var dragLength = (sizeConfPageY - e.touches[0].pageY) * dragScaleP
  249. if (initDragCutH >= dragLength && initDragCutT > dragLength) {
  250. if (dragLength < 0 && Math.abs(dragLength) >= initDragCutH) return
  251. this.setData({
  252. cutT: initDragCutT - dragLength,
  253. cutH: initDragCutH + dragLength
  254. })
  255. } else {
  256. return;
  257. }
  258. break;
  259. case 'bottom':
  260. var dragLength = (sizeConfPageY - e.touches[0].pageY) * dragScaleP
  261. // console.log(this.data.cropperH > this.data.cutT + this.data.cutH)
  262. // console.log(dragLength)
  263. // console.log(initDragCutH >= dragLength)
  264. // console.log(this.data.cropperH > initDragCutT + this.data.cutH)
  265. // 必须是 dragLength 向上缩小的时候必须小于原本的高度
  266. if (initDragCutH >= dragLength) {
  267. // 如果 移动小于0 说明是在往下啦 放大裁剪的高度 这样一来 图片的高度 最大 等于 图片的top值加 当前图片的高度 否则就说明超出界限
  268. if (dragLength < 0 && this.data.cropperH > initDragCutT + this.data.cutH) {
  269. this.setData({
  270. cutH: initDragCutH - dragLength
  271. })
  272. }
  273. // 如果是移动 大于0 说明在缩小 只需要缩小的距离小于原本裁剪的高度就ok
  274. if (dragLength > 0) {
  275. this.setData({
  276. cutH: initDragCutH - dragLength
  277. })
  278. } else {
  279. return
  280. }
  281. } else {
  282. return
  283. }
  284. break;
  285. case 'rightBottom':
  286. var dragLengthX = (sizeConfPageX - e.touches[0].pageX) * dragScaleP
  287. var dragLengthY = (sizeConfPageY - e.touches[0].pageY) * dragScaleP
  288. if (initDragCutH >= dragLengthY && initDragCutW >= dragLengthX) {
  289. // bottom 方向的变化
  290. if ((dragLengthY < 0 && this.data.cropperH > initDragCutT + this.data.cutH) || (dragLengthY > 0)) {
  291. this.setData({
  292. cutH: initDragCutH - dragLengthY
  293. })
  294. }
  295. // right 方向的变化
  296. if ((dragLengthX < 0 && this.data.cropperW > initDragCutL + this.data.cutW) || (dragLengthX > 0)) {
  297. this.setData({
  298. cutW: initDragCutW - dragLengthX
  299. })
  300. } else {
  301. return
  302. }
  303. } else {
  304. return
  305. }
  306. break;
  307. default:
  308. break;
  309. }
  310. },
  311. /**
  312. * 生命周期函数--监听页面加载
  313. */
  314. onLoad: function (options) {
  315. this.setData({
  316. imageSrc: 'https://wx3.sinaimg.cn/orj360/6b03f0e6gy1h6c1mivf4lj20u01400wu.jpg'
  317. })
  318. },
  319. /**
  320. * 生命周期函数--监听页面初次渲染完成
  321. */
  322. onReady: function () {
  323. wx.showLoading({
  324. title: '图片加载中...',
  325. })
  326. wx.getImageInfo({
  327. src: this.data.imageSrc,
  328. success: res=>{
  329. var innerAspectRadio = res.width / res.height;
  330. // 根据图片的宽高显示不同的效果 保证图片可以正常显示
  331. if (innerAspectRadio >= 1) {
  332. this.setData({
  333. cropperW: windowWRPX,
  334. cropperH: windowWRPX / innerAspectRadio,
  335. // 初始化left right
  336. cropperL: Math.ceil((windowWRPX - windowWRPX) / 2),
  337. cropperT: Math.ceil((windowWRPX - windowWRPX / innerAspectRadio) / 2),
  338. // 裁剪框 宽高
  339. cutW: windowWRPX - 200,
  340. cutH: windowWRPX / innerAspectRadio - 200,
  341. cutL: Math.ceil((windowWRPX - windowWRPX + 200) / 2),
  342. cutT: Math.ceil((windowWRPX / innerAspectRadio - (windowWRPX / innerAspectRadio - 200)) / 2),
  343. // 图片缩放值
  344. scaleP: res.width * pixelRatio / windowWRPX,
  345. // 图片原始宽度 rpx
  346. imageW: res.width * pixelRatio,
  347. imageH: res.height * pixelRatio
  348. })
  349. } else {
  350. this.setData({
  351. cropperW: windowWRPX * innerAspectRadio,
  352. cropperH: windowWRPX,
  353. // 初始化left right
  354. cropperL: Math.ceil((windowWRPX - windowWRPX * innerAspectRadio) / 2),
  355. cropperT: Math.ceil((windowWRPX - windowWRPX) / 2),
  356. // 裁剪框的宽高
  357. cutW: windowWRPX * innerAspectRadio - 200,
  358. cutH: 200,
  359. cutL: Math.ceil((windowWRPX * innerAspectRadio - (windowWRPX * innerAspectRadio - 50)) / 2),
  360. cutT: Math.ceil((windowWRPX - 200) / 2),
  361. // 图片缩放值
  362. scaleP: res.width * pixelRatio / windowWRPX,
  363. // 图片原始宽度 rpx
  364. imageW: res.width * pixelRatio,
  365. imageH: res.height * pixelRatio
  366. })
  367. }
  368. this.setData({
  369. isShowImg: true
  370. })
  371. wx.hideLoading()
  372. }
  373. })
  374. },
  375. /**
  376. * 生命周期函数--监听页面显示
  377. */
  378. onShow: function () {
  379. },
  380. /**
  381. * 生命周期函数--监听页面隐藏
  382. */
  383. onHide: function () {
  384. },
  385. /**
  386. * 生命周期函数--监听页面卸载
  387. */
  388. onUnload: function () {
  389. },
  390. /**
  391. * 页面相关事件处理函数--监听用户下拉动作
  392. */
  393. onPullDownRefresh: function () {
  394. },
  395. /**
  396. * 页面上拉触底事件的处理函数
  397. */
  398. onReachBottom: function () {
  399. },
  400. /**
  401. * 用户点击右上角分享
  402. */
  403. onShareAppMessage: function () {
  404. }
  405. })

css

  1. .wx-corpper{
  2. position: relative;
  3. overflow: hidden;
  4. -webkit-user-select: none;
  5. -moz-user-select: none;
  6. -ms-user-select: none;
  7. user-select: none;
  8. -webkit-tap-highlight-color: transparent;
  9. -webkit-touch-callout: none;
  10. box-sizing: border-box;
  11. }
  12. .wx-corpper-content{
  13. position: absolute;
  14. top: 0;
  15. right: 0;
  16. bottom: 0;
  17. left: 0;
  18. }
  19. .wx-corpper-content image {
  20. display: block;
  21. width: 100%;
  22. min-width: 0 !important;
  23. max-width: none !important;
  24. height: 100%;
  25. min-height: 0 !important;
  26. max-height: none !important;
  27. image-orientation: 0deg !important;
  28. margin: 0 auto;
  29. }
  30. /* 移动图片效果 */
  31. .wx-cropper-drag-box{
  32. position: absolute;
  33. top: 0;
  34. right: 0;
  35. bottom: 0;
  36. left: 0;
  37. cursor: move;
  38. background: rgba(0,0,0,0.6);
  39. z-index: 1;
  40. }
  41. /* 内部的信息 */
  42. .wx-corpper-crop-box{
  43. position: absolute;
  44. width: 500rpx;
  45. height: 500rpx;
  46. background: rgba(255,255,255,0.3);
  47. z-index: 2;
  48. }
  49. .wx-corpper-crop-box .wx-cropper-view-box {
  50. position: relative;
  51. display: block;
  52. width: 100%;
  53. height: 100%;
  54. overflow: visible;
  55. outline: 1px solid #69f;
  56. outline-color: rgba(102, 153, 255, .75)
  57. }
  58. /* 横向虚线 */
  59. .wx-cropper-dashed-h{
  60. position: absolute;
  61. top: 33.33333333%;
  62. left: 0;
  63. width: 100%;
  64. height: 33.33333333%;
  65. border-top: 1px dashed rgba(255,255,255,0.5);
  66. border-bottom: 1px dashed rgba(255,255,255,0.5);
  67. }
  68. /* 纵向虚线 */
  69. .wx-cropper-dashed-v{
  70. position: absolute;
  71. left: 33.33333333%;
  72. top: 0;
  73. width: 33.33333333%;
  74. height: 100%;
  75. border-left: 1px dashed rgba(255,255,255,0.5);
  76. border-right: 1px dashed rgba(255,255,255,0.5);
  77. }
  78. /* 四个方向的线 为了之后的拖动事件*/
  79. .wx-cropper-line-t{
  80. position: absolute;
  81. display: block;
  82. width: 100%;
  83. background-color: #69f;
  84. top: 0;
  85. left: 0;
  86. height: 1px;
  87. opacity: 0.1;
  88. cursor: n-resize;
  89. }
  90. .wx-cropper-line-t::before{
  91. content: '';
  92. position: absolute;
  93. top: 50%;
  94. right: 0rpx;
  95. width: 100%;
  96. -webkit-transform: translate3d(0,-50%,0);
  97. transform: translate3d(0,-50%,0);
  98. bottom: 0;
  99. height: 41rpx;
  100. background: transparent;
  101. z-index: 11;
  102. }
  103. .wx-cropper-line-r{
  104. position: absolute;
  105. display: block;
  106. background-color: #69f;
  107. top: 0;
  108. right: 0px;
  109. width: 1px;
  110. opacity: 0.1;
  111. height: 100%;
  112. cursor: e-resize;
  113. }
  114. .wx-cropper-line-r::before{
  115. content: '';
  116. position: absolute;
  117. top: 0;
  118. left: 50%;
  119. width: 41rpx;
  120. -webkit-transform: translate3d(-50%,0,0);
  121. transform: translate3d(-50%,0,0);
  122. bottom: 0;
  123. height: 100%;
  124. background: transparent;
  125. z-index: 11;
  126. }
  127. .wx-cropper-line-b{
  128. position: absolute;
  129. display: block;
  130. width: 100%;
  131. background-color: #69f;
  132. bottom: 0;
  133. left: 0;
  134. height: 1px;
  135. opacity: 0.1;
  136. cursor: s-resize;
  137. }
  138. .wx-cropper-line-b::before{
  139. content: '';
  140. position: absolute;
  141. top: 50%;
  142. right: 0rpx;
  143. width: 100%;
  144. -webkit-transform: translate3d(0,-50%,0);
  145. transform: translate3d(0,-50%,0);
  146. bottom: 0;
  147. height: 41rpx;
  148. background: transparent;
  149. z-index: 11;
  150. }
  151. .wx-cropper-line-l{
  152. position: absolute;
  153. display: block;
  154. background-color: #69f;
  155. top: 0;
  156. left: 0;
  157. width: 1px;
  158. opacity: 0.1;
  159. height: 100%;
  160. cursor: w-resize;
  161. }
  162. .wx-cropper-line-l::before{
  163. content: '';
  164. position: absolute;
  165. top: 0;
  166. left: 50%;
  167. width: 41rpx;
  168. -webkit-transform: translate3d(-50%,0,0);
  169. transform: translate3d(-50%,0,0);
  170. bottom: 0;
  171. height: 100%;
  172. background: transparent;
  173. z-index: 11;
  174. }
  175. .wx-cropper-point{
  176. width: 5px;
  177. height: 5px;
  178. background-color: #69f;
  179. opacity: .75;
  180. position: absolute;
  181. z-index: 3;
  182. }
  183. .point-t{
  184. top: -3px;
  185. left: 50%;
  186. margin-left: -3px;
  187. cursor: n-resize;
  188. }
  189. .point-tr{
  190. top: -3px;
  191. left: 100%;
  192. margin-left: -3px;
  193. cursor: n-resize;
  194. }
  195. .point-r{
  196. top: 50%;
  197. left:100%;
  198. margin-left: -3px;
  199. margin-top: -3px;
  200. cursor: n-resize;
  201. }
  202. .point-rb{
  203. left: 100%;
  204. top: 100%;
  205. -webkit-transform: translate3d(-50%,-50%,0);
  206. transform: translate3d(-50%,-50%,0);
  207. cursor: n-resize;
  208. width: 24rpx;
  209. height: 24rpx;
  210. background-color: #69f;
  211. position: absolute;
  212. z-index: 1112;
  213. opacity: 1;
  214. }
  215. .point-b{
  216. left:50%;
  217. top: 100%;
  218. margin-left: -3px;
  219. margin-top: -3px;
  220. cursor: n-resize;
  221. }
  222. .point-bl{
  223. left:0%;
  224. top: 100%;
  225. margin-left: -3px;
  226. margin-top: -3px;
  227. cursor: n-resize;
  228. }
  229. .point-l{
  230. left:0%;
  231. top: 50%;
  232. margin-left: -3px;
  233. margin-top: -3px;
  234. cursor: n-resize;
  235. }
  236. .point-lt{
  237. left:0%;
  238. top: 0%;
  239. margin-left: -3px;
  240. margin-top: -3px;
  241. cursor: n-resize;
  242. }
  243. /* 裁剪框预览内容 */
  244. .wx-cropper-viewer{
  245. position: relative;
  246. width: 100%;
  247. height: 100%;
  248. overflow: hidden;
  249. }
  250. .wx-cropper-viewer image{
  251. position: absolute;
  252. z-index: 2;
  253. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议