目录

页面跳转时,有渐入渐出的动效

问题现象

页面跳转时,有渐入渐出的动效,新旧页面内容出现重叠显示。

背景知识

问题定位

  1. 使用DevEco Testing查看该页面的组件,跳转前后的页面分别通过不同的Web组件显示。

  2. 查看跳转之后的Web组件的相关设置,发现应用transition属性设置了透明度渐变的过渡效果。
    import { webview } from '@kit.ArkWeb';
    
    @Entry
    @Component
    struct WebVideo {
      controller: webview.WebviewController = new webview.WebviewController();
      @State isShowNewWeb: boolean = false;
    
      build() {
        Stack() {
          Column() {
            Web({ src: $rawfile('VideoList.html'), controller: this.controller })
              .height('100%')
              .width('100%')
              .fileAccess(true)
              .geolocationAccess(false)
              .onLoadIntercept((event) => {
                if (event.data.getRequestUrl() === 'resource://rawfile/index_cn.html') {
                  this.isShowNewWeb = true;
                  return true; // 拦截此次跳转
                } else {
                  return false; // 允许跳转
                }
              });
          };
    
          if (this.isShowNewWeb) {
            Web({ src: $rawfile('index_cn.html'), controller: this.controller })
              .height('100%')
              .width('100%')
              .fileAccess(true)
              .geolocationAccess(false)
              .transition(TransitionEffect.OPACITY.animation({ duration: 2000, curve: Curve.Ease })); // 设置透明度渐变的过渡效果
          }
        }
        .height('100%')
        .width('100%');
      }
    }

分析结论

在页面跳转过程中,使用新的Web组件呈现内容,同时对跳转后的Web组件应用transition属性设置了透明度渐变转场效果。

修改建议