Browse Source

限制滑动范围

hella_online_20240829
wangyufei 5 months ago
parent
commit
89a176544d
  1. 29
      src/mycomponents/scan/winScanButton.vue

29
src/mycomponents/scan/winScanButton.vue

@ -28,22 +28,35 @@
}, },
props: { props: {
},
created() {
}, },
methods: { methods: {
getScreenWidth() {
const systemInfo = uni.getSystemInfoSync();
return systemInfo.windowWidth; // px
},
getScreenHeight() {
const systemInfo = uni.getSystemInfoSync();
return systemInfo.windowHeight; // px
},
handleTouchStart(e) { handleTouchStart(e) {
this.btnX = e.changedTouches[0].clientX-e.currentTarget.offsetLeft this.btnX = e.changedTouches[0].clientX-e.currentTarget.offsetLeft
this.btnY = e.changedTouches[0].clientY-e.currentTarget.offsetTop this.btnY = e.changedTouches[0].clientY-e.currentTarget.offsetTop
}, },
handleTouchMove(e) { handleTouchMove(e) {
console.log("handleTouchMove",e); let maxLeft = this.getScreenWidth() - 60
let maxTop = this.getScreenHeight() - 40
console.log('maxTop',maxTop)
// this.$refs.scanRef.$el.style.left = e.changedTouches[0].clientX-this.btnX+'px' // this.$refs.scanRef.$el.style.left = e.changedTouches[0].clientX-this.btnX+'px'
// this.$refs.scanRef.$el.style.top = e.changedTouches[0].clientY-this.btnY+'px' // this.$refs.scanRef.$el.style.top = e.changedTouches[0].clientY-this.btnY+'px'
this.viewLeft = e.changedTouches[0].clientX-this.btnX+'px' let newLeft = e.changedTouches[0].clientX-this.btnX
this.viewTop = e.changedTouches[0].clientY-this.btnY+'px' let newTop = e.changedTouches[0].clientY-this.btnY
console.log('newTop',newTop)
if(newTop>0&&newTop<maxTop){
this.viewTop = newTop+'px'
}
if(newLeft>0&&newLeft<maxLeft){
this.viewLeft = newLeft+'px'
}
// const query = uni.createSelectorQuery().in(this) // const query = uni.createSelectorQuery().in(this)
// console.log('scanRef',query.select("#scanRef")) // console.log('scanRef',query.select("#scanRef"))
// query.select("#scanRef").boundingClientRect((data=>{ // query.select("#scanRef").boundingClientRect((data=>{

Loading…
Cancel
Save