首页 > 其他分享 >181 Animation Basics & CSS Transitions

181 Animation Basics & CSS Transitions

时间:2024-09-11 21:25:10浏览次数:3  
标签:vue animatedBlock color width 181 background Transitions border Animation

实现点击Animate,上面的方块移动

示例

步骤

1、为Animate按钮添加@click方法animateBlock

<button @click="animateBlock">Animate</button>

2、添加animatedBlock变量控制是否可以移动

data() {
    return {
      animatedBlock: false,
      dialogIsVisible: false
    };
  },

3、实现animateBlock方法

animateBlock() {
  this.animatedBlock = !this.animatedBlock;
},

4、再绑定一个class给方块

<div class="block" :class="{ animate: animatedBlock }"></div>

5、新建class animate

.animate {
  transform: translateX(-150px);
}

6、为了实现动画效果,在.block中添加transition

.block {
  width: 8rem;
  height: 8rem;
  background-color: #290033;
  margin-bottom: 2rem;
  transition: transform 0.3s ease-out;
}

完整代码

BaseModal.vue

<template>
  <div class="backdrop" @click="$emit('close')"></div>
  <dialog open>
    <slot></slot>
  </dialog>
</template>

<script>
export default {
  emits: ['close'],
};
</script>

<style scoped>
.backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 10;
  background-color: rgba(0, 0, 0, 0.75);
}

dialog {
  position: fixed;
  top: 30vh;
  width: 30rem;
  left: calc(50% - 15rem);
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  border-radius: 12px;
  padding: 1rem;
  background-color: white;
  z-index: 100;
  border: none;
}
</style>

App.vue

<template>
  <div class="container">
    <div class="block" :class="{ animate: animatedBlock }"></div>
    <button @click="animateBlock">Animate</button>
  </div>
  <base-modal @close="hideDialog" v-if="dialogIsVisible">
    <p>This is a test dialog!</p>
    <button @click="hideDialog">Close it!</button>
  </base-modal>
  <div class="container">
    <button @click="showDialog">Show Dialog</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      animatedBlock: false,
      dialogIsVisible: false
    };
  },
  methods: {
    animateBlock() {
      this.animatedBlock = !this.animatedBlock;
    },
    showDialog() {
      this.dialogIsVisible = true;
    },
    hideDialog() {
      this.dialogIsVisible = false;
    },

  },
};
</script>

<style>
* {
  box-sizing: border-box;
}

html {
  font-family: sans-serif;
}

body {
  margin: 0;
}

button {
  font: inherit;
  padding: 0.5rem 2rem;
  border: 1px solid #810032;
  border-radius: 30px;
  background-color: #810032;
  color: white;
  cursor: pointer;
}

button:hover,
button:active {
  background-color: #a80b48;
  border-color: #a80b48;
}

.block {
  width: 8rem;
  height: 8rem;
  background-color: #290033;
  margin-bottom: 2rem;
  transition: transform 0.3s ease-out;
}

.container {
  max-width: 40rem;
  margin: 2rem auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding: 2rem;
  border: 2px solid #ccc;
  border-radius: 12px;
}

.animate {
  transform: translateX(-150px);
}
</style>

main.js

import { createApp } from 'vue';

import App from './App.vue';
import BaseModal from './components/BaseModal.vue';

const app = createApp(App);

app.component('base-modal', BaseModal);

app.mount('#app');

标签:vue,animatedBlock,color,width,181,background,Transitions,border,Animation
From: https://blog.csdn.net/KevinHuang2088/article/details/142150617

相关文章

  • 1818. 绝对差值和
    题目链接1818.绝对差值和思路排序+二分题解链接运用「二分」找最佳替换方案关键点转换为查找最小值delta:对nums1进行排序后,从中二分查找nums2[i]的最接近值(考虑到绝对值,需要检查left&right两个位置)时间复杂度\(O(n\logn)\)空间复杂度\(O(n)\)代......
  • 计算机毕业设计必看必学!!11819 ssm球鞋资讯交流平台,原创定制程序, java、PHP、python
    摘 要随着科学技术的飞速发展,社会的方方面面、各行各业都在努力与现代的先进技术接轨,通过科技手段来提高自身的优势,球鞋资讯交流平台当然也不能排除在外。球鞋资讯交流平台是以实际运用为开发背景,运用软件工程原理和开发方法,采用 SSM技术构建的一个管理平台。整个开发过程......
  • 如何集成Android平台GB28181设备接入模块?
    技术优势大牛直播SDK的Android平台GB28181设备接入模块在适用场景、音视频能力、定位与通信、数据管理、安全性与稳定性、配置与扩展性以及集成与维护等方面均表现出显著的优势。这些优势使得该模块在视频监控、巡检抢修、远程指挥等多个领域具有广泛的应用前景和重要的应用价值。......
  • GB28181规范中broadcast和talk模式实际场景时间差别在哪里?
    好多开发者对GB28181规范里面,broadcast和talk模式区分不清,今天借此机会,针对GB28181标准中的Broadcast(广播)和Talk(对讲)是两种不同的通信模式,它们在视频监控系统中扮演着不同的角色,做个基础的扫盲,二者具有以下区别:1.功能和用途Broadcast(广播): 功能:主要用于平台侧向设备侧发送单向的通......
  • 2181. 合并零之间的节点
    给你一个链表的头节点 head ,该链表包含由 0 分隔开的一连串整数。链表的 开端 和 末尾 的节点都满足 Node.val==0 。对于每两个相邻的 0 ,请你将它们之间的所有节点合并成一个节点,其值是所有已合并节点的值之和。然后将所有 0 移除,修改后的链表不应该含有任何 0......
  • [LeetCode] 2181. Merge Nodes in Between Zeros
    Youaregiventheheadofalinkedlist,whichcontainsaseriesofintegersseparatedby0's.ThebeginningandendofthelinkedlistwillhaveNode.val==0.Foreverytwoconsecutive0's,mergeallthenodeslyinginbetweenthemintoasing......
  • 基于java的个性化图书推荐系统(11181)
     有需要的同学,源代码和配套文档领取,加文章最下方的名片哦一、项目演示项目演示视频二、资料介绍完整源代码(前后端源代码+SQL脚本)配套文档(LW+PPT+开题报告)远程调试控屏包运行三、技术介绍Java语言SSM框架SpringBoot框架Vue框架JSP页面Mysql数据库IDEA/Eclipse开发......
  • PM864AK01-eA-3BSE018161R2 CPU单元处理器
    ABBPM864AKO1 eA3BSE018161R2  CPU单元处理器产品详情:CPU单元处理器的应用领域与处理器单元套件相似,可能包括但不限于以下几个方面:1.工业自动化控制:CPU单元处理器可以用于工业过程控制、生产线自动化、机械控制等领域,以实现各种自动化控制任务。2.分布式控制系统......
  • https://www.zhihu.com/pin/1814343061205024769
    在开发Docmatix时,我们发现经其微调的Florence-2在DocVQA任务上表现出色,但在基准测试中得分仍比较低。为了提高基准测试得分,我们必须在DocVQA数据集上进一步对模型进行微调,以学习该基准测试的语法风格。有意思的是,人类评估者认为经额外微调后,模型的表现似乎反而不如仅在Do......
  • Android终端如何快速接入GB28181平台实现实时音视频回传
    技术背景GB28181是由中国国家标准委员会发布的基于IP网络的安防视频监控标准。Android平台GB28181设备对接模块,主要涉及到视频监控领域,可实现不具备国标音视频能力的Android终端,通过平台注册接入到现有的GB/T28181—2016服务,可用于如执法记录仪、智能安全帽、智能监控、智慧零售、......