<p>&quot;&quot;&quot;<template>\n  <div>\n    &lt;transition name=&quot;fade&quot;&gt;\n      &lt;div v-if=&quot;showPage1&quot; class=&quot;page&quot;&gt;\n        <h1>第一页</h1>\n        &lt;button @click=&quot;showPage1 = false&quot;&gt;下一页</button>\n      </div>\n    </transition>\n    &lt;transition name=&quot;fade&quot;&gt;\n      &lt;div v-if=&quot;!showPage1&quot; class=&quot;page&quot;&gt;\n        <h1>第二页</h1>\n        &lt;button @click=&quot;showPage1 = true&quot;&gt;上一页</button>\n      </div>\n    </transition>\n  </div>\n</template>\n\n<script>\n  export default {\n    data() {\n      return {\n        showPage1: true\n      }\n    }\n  }\n</script>\n\n<style>\n  .fade-enter-active, .fade-leave-active {\n    transition: opacity 0.5s;\n  }\n  .fade-enter, .fade-leave-to {\n    opacity: 0;\n  }\n  .page {\n    width: 300px;\n    height: 300px;\n    background-color: #ccc;\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    justify-content: center;\n  }\n</style>\n&quot;&quot;&quot;. 在上述代码中,我们使用了 Vue 的 <code>&lt;transition&gt;</code> 组件来实现过渡效果,并给它一个 <code>name</code> 属性来定义过渡的名称。在 CSS 中,我们通过 <code>.fade-enter-active</code> 和 <code>.fade-leave-active</code> 来定义过渡动画的持续时间和属性,通过 <code>.fade-enter</code> 和 <code>.fade-leave-to</code> 来定义过渡的初始状态和结束状态。\n\n在 <code>&lt;div&gt;</code> 元素中通过 <code>v-if</code> 指令来根据 <code>showPage1</code> 的值来切换页面的显示和隐藏。当点击按钮时,通过修改 <code>showPage1</code> 的值来切换页面。\n\n当 <code>showPage1</code> 的值为 <code>true</code> 时,显示第一页的内容,点击按钮后将 <code>showPage1</code> 的值设为 <code>false</code>,然后通过过渡效果实现第一页的淡出,同时第二页淡入。当 <code>showPage1</code> 的值为 <code>false</code> 时,显示第二页的内容,点击按钮后将 <code>showPage1</code> 的值设为 <code>true</code>,然后通过过渡效果实现第二页的淡出,同时第一页淡入。\n\n这样就实现了小说覆盖效果切换。你可以根据实际需要修改页面内容和样式来适应你的项目。</p>

原文地址: https://www.cveoy.top/t/topic/pEP5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录