当前位置:网站首页>H5 van popup full screen pop-up window, simulates the page fallback effect, supports the return button in the upper left corner, and is suitable for physical return, side sliding and bottom return key

H5 van popup full screen pop-up window, simulates the page fallback effect, supports the return button in the upper left corner, and is suitable for physical return, side sliding and bottom return key

2022-06-10 20:34:00 Half Annie

First step :
1、 Definition animateDuration Variable
2、 Definition open Event execution method selectProjectOpenHandler
3、 Definition close Event execution method selectProjectCloseHandler

data () {
    
    return {
    
      animateDuration: 0.3 //  Default pop-up animation time 0.3s
    }
},

The second step :van-popup Use :

<!-- van-popup  -->
 <van-popup 
    v-model="_show" 
    position="right" 
    :overlay="false"
   :style="{ width: '100%', height: '100%' }" 
   :duration="animateDuration" 
    @open="selectProjectOpenHandler" 
    @close="selectProjectCloseHandler">
                    <!--  Pop-up content  -->
</van-popup>

The third step :
selectProjectOpenHandler:

// popup open 
selectProjectOpenHandler () {
    
  window.history.pushState(null, null, '#') //  Simulate a new page history Record 
  window.addEventListener('popstate', this.popstateHandler) // add to popstate Event monitoring 
}
popstateHandler (e) {
    
 	this.animateDuration = 0 //  Prevent side slip from animating many times 
  	this._show = false // close van-popup
}

selectProjectCloseHandler:

// popup close 
selectProjectCloseHandler () {
    
    window.removeEventListener('popstate', this.popstateHandler, false)
},

Step four : Button returns the method goBack ( important !)

goBack () {
    
  window.history.back() //  Delete van-popup Added when opening history
  this._show = false
},

The bar effect !!! Specific business needs can be adjusted by themselves

原网站

版权声明
本文为[Half Annie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101929400313.html