애플릿 전역 드래그 플로팅 플러그인

4028 단어 위챗 애플릿
프로젝트 원본~~ 앱이 필요합니다.js는 전역 변수를 설정하여 전역적으로 숨겨진 위치를 통일적으로 보여 줍니다.

  
    
    
    
    
      
        
    
    
  
page{
  height: 100%;
}
.fixed-area{
  width: 100%;
  height: 100%;
  -webkit-overflow-scrolling : touch;
}
.ball{
  position: fixed;
  background: #fff;
  box-shadow: 0 0 5px #ddd; 
  border: #eee;
  width:100rpx;
  height:100rpx;
  text-align: center;
  z-index: 1002;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.close-area{
  position: fixed;
  width: 500rpx;
  height: 500rpx;
  right: -250rpx;
  bottom: -250rpx;
  background: #eb5352;
  border-radius: 50%;
  z-index: 1001;
}
.big{
  right: -230rpx;
  bottom: -230rpx;
}

.close-icon{
  height: 70rpx;
  width: 70rpx;
  position: absolute;
  top: 90rpx;
  left: 110rpx;
}
.close-text{
  position: absolute;
  top: 185rpx;
  left: 98rpx;
  font-size: 24rpx;
  color: #fff;
}
.return-icon{
  width: 40rpx;
  height: 40rpx;
  display: block;
  margin-bottom: 3rpx;
}
.return-text{
  color: #ca7;
  font-size: 18rpx;
  display: block;
}
// assembly/returnBall/returnBall.js
const app = getApp();
Component({

  /**
   *        
   */
  data: {
    x: app.globalData.returnBall.x,
    y: app.globalData.returnBall.y,
    movableBlo: app.globalData.returnBall.show,
    animate: false
  },
  methods: {
    change(e) {
      let screenWidth = this.data.screenWidth,
        screenHeight = this.data.screenHeight;
      let x = e.detail.x
      let y = e.detail.y
      if (x > screenWidth - 250 && y > screenHeight - 250) {
        this.setData({
          alreadyClose: true
        })
      } else {
        this.setData({
          alreadyClose: false
        })
      }
    },
    returnMini() {
      app.navigate.returnBack()
    },
    touchStart() {
      this.setData({
        closeArea: true
      })
    },
    end(e) {
      let screenWidth = this.data.screenWidth,
        screenHeight = this.data.screenHeight,
        x = e.changedTouches[0].pageX,
        y = e.changedTouches[0].pageY;
      if (x > screenWidth - 100 && y > screenHeight - 100) {
        app.globalData.returnBall.show = false
        this.setData({
          movableBlo: false
        })
      }
      setTimeout(() => {
        app.globalData.returnBall.x = screenWidth;
        app.globalData.returnBall.y = y;
        this.setData({
          animate: true,
          x: screenWidth,
          y,
          closeArea: false
        })
      }, 300)
    },
    scrollPage(e) {
      let pages = getCurrentPages();
      let curPage = pages[pages.length - 1];
      if (curPage.myPageScroll) {
        curPage.myPageScroll(e)
      }
    },
    toBottom() {
      let pages = getCurrentPages();
      let curPage = pages[pages.length - 1];
      if (curPage.toBottom) {
        curPage.toBottom()
      }
    }
  },
  pageLifetimes: {
    show() {
      this.setData({
        x: app.globalData.returnBall.x,
        y: app.globalData.returnBall.y,
        movableBlo: app.globalData.returnBall.show,
        animate: false
      })
      this.setData({
        screenWidth: wx.getSystemInfoSync().windowWidth,
        screenHeight: wx.getSystemInfoSync().windowHeight
      })
    },
  }
})

좋은 웹페이지 즐겨찾기