Giter Club home page Giter Club logo

Comments (3)

easonyq avatar easonyq commented on July 30, 2024

满足这个需求目前有两种办法:

  1. 覆盖CSS。目前的动画主要就是 <div class="mip-page-loading-wrapper">, <iframe class="mip-page__iframe">, <div class="mip-page-fade-header-wrapper"> 这几个元素在进行。他们都遵循 Vue 的 transition 规范,在动画的各个阶段都会有诸如 slide-enter, slide-enter-to, slide-enter-active 这样的 class。只需要覆盖这些 class,就可以控制动画过程。这也是最无损最推荐的方法。
  2. 继承子类并重写切换页面和动画相关的方法。但目前这部分的代码都在page中而不在shell中,我正在进行一次重构,把这部分代码移动到 shell 中来。不过即便完成之后,因为动画和切换页面在一起,还要负责创建 iframe,添加路由规则等等,实际上我觉得这不算是个太好的办法。

from mip2.

easonyq avatar easonyq commented on July 30, 2024

#68 一样,解决了会一并关闭

from mip2.

easonyq avatar easonyq commented on July 30, 2024

代码已经合入完毕了。

动画钩子函数

经过重构的 mip-shell 中,会有3个处理动画的函数,子类可以关注:

  • beforeSwitchPage(options)
    在切换动画之前调用,供子类继承并修改(如创建自己的动画层等)

  • afterSwitchPage(options)
    在切换动画完成后调用,供子类继承并修改(如给其他组件发送通知等)

  • switchPage(options)
    动画切换逻辑全部在这里,父类已有实现。但子类如有需要也可继承修改,非必须情况尽量不要继承。

switchPage 内部处理逻辑

switchPage 内部还根据动画的方向,是否创建 iframe,是否要跳过动画区分为6个细分方法。子类也可以继承其中的某一个或几个,来实现对动画的精确控制。
switchPage 一样,非必须情况尽量不要继承。

在介绍具体方法前,先明晰3组概念:

  1. 是否需要动画
    如点击浏览器的前进后退,没有动画效果;点击链接和头部的后退按钮,有动画效果。

  2. 是否创建 iframe
    点击链接打开新页面时(或者直接调用 viewer.open 时)会创建 iframe 并把新页面放入其中。而浏览器的前进后退时不创建 iframe,只调用已有的 iframe 展现。

  3. 动画方向
    这里的动画方向并不是视觉上的从左到右还是从右到左,而是指逻辑上的方向,分前进/后退。
    只是在默认情况下,前进采用目标页面从右到左进入屏幕的方式;后退等价于当前页面向右侧退出屏幕,目标页面出现在下方的方式。

不需要动画时

创建 iframe 不创建 iframe
skipTransitionAndCreate(options) skipTransition(optios)

需要动画时

创建 iframe 不创建 iframe
前进 forwardTransitionAndCreate(options) forwardTransition(optios)
后退 backwardTransitionAndCreate(options) backwardTransition(optios)

参数对象 options

所有这些方法的参数对象 options 格式均相同,如下:

  • targetPageId
  • targetPageMeta
  • sourcePageId
  • sourcePageMeta
  • newPage 是否创建了 iframe
  • isForward 是否前进
  • onComplete 动画完成后的回调函数

其中 newPageisForward 的值和方法名是一致的。
forwardTransitionAndCreate 方法内 newPagetrueisForwardtruebackwardTransition 方法内 newPagefalseisForwardfalse
而单纯的钩子函数 (如 afterSwitchPage)则均有可能,由子类自行判断并处理。

from mip2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.