DeepSeek 助力 Vue 开发:打造丝滑的点击动画(Click Animations)

前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕

共同探索软件研发!敬请关注【宝码香车】
关注描述

csdngif标识

目录

  • DeepSeek 助力 Vue 开发:打造丝滑的点击动画(Click Animations)
    • 📚前言
    • 📚页面效果
    • 📚指令输入
      • 属性定义
        • 1. 动画类型相关属性
        • 2. 样式相关属性
        • 3. 动画次数和循环相关属性
        • 4. 状态控制属性
      • 事件定义
        • 1. 动画开始事件
        • 2. 动画结束事件
        • 3. 点击事件
      • 其他
        • 1. 兼容性处理
        • 2. 文档和示例
        • 3. 性能优化
        • 4. 可扩展性
        • 5. 错误处理
    • 📚think
      • 📘组件代码
    • 📚代码测试
    • 📚整理后主要代码
      • 📘定义组件 src\components\ClickAnimations\ClickAnimations.vue
      • 📘调用 src\views\ClickAnimationsView.vue
    • 📚为测试代码正常跑通,附其他基本代码
      • 📘编写路由 src\router\index.js
      • 📘编写展示入口 src\App.vue
    • 📚页面效果


📚📗📕📘📖🕮💡📝🗂️✍️🛠️💻🚀🎉🏗️🌐🖼️🔗📊👉🔖⚠️🌟🔐⬇️·正文开始⬇️·🎥😊🎓📩😺🌈🤝🤖📜📋🔍✅🧰❓📄📢📈 🙋0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟🆗*️⃣#️⃣

DeepSeek 助力 Vue 开发:打造丝滑的点击动画(Click Animations)

📚前言

在社交媒体和各类技术论坛上,用户对 DeepSeek 的评价如潮水般涌来,其中不乏对其强大功能和出色表现的高度赞誉。许多用户分享了自己使用 DeepSeek 解决实际问题的案例,这些案例生动地展现了 DeepSeek 在不同领域的应用价值。

在学术研究领域,一位生物学博士分享了他的经历。他在研究一种罕见疾病的发病机制时,需要查阅大量的文献资料。以往,他需要花费数周的时间在海量的学术论文中筛选和整理信息,而这次他借助 DeepSeek,仅用了几天的时间就完成了这项工作。DeepSeek 不仅能够快速准确地理解论文的内容,还能根据他的研究需求,提供相关的研究思路和建议。例如,在分析一篇关于基因调控的论文时,DeepSeek 能够指出论文中尚未深入探讨的潜在研究方向,为他的研究提供了新的灵感。他感慨地说:“DeepSeek 就像是我的学术助手,大大提高了我的研究效率,让我能够更专注于实验和数据分析。”

📚页面效果

页面效果

📚指令输入

已经创建好了一个基于Vue3的组合式API的项目(Composition API),并能正常运行起来,请帮我用 Vue3的组合式API(Composition API) 生成一个 点击动画(Click Animations) 的功能组件,所有代码都保存在components/ClickAnimations 下的文件夹中。功能组件的script标签中只有setup属性,使用普通 JavaScript 实现,不使用TypeScript。
功能要有,如下属性:

属性定义

1. 动画类型相关属性
  • animationType:指定点击时触发的动画类型,如 fade(淡入淡出)、scale(缩放)、slide(滑动)等。可以使用字符串类型,方便后续扩展更多动画类型。
  • animationDuration:动画持续的时间,单位可以是毫秒(ms)。使用数字类型,让用户可以自定义动画的快慢。
  • animationDelay:动画开始前的延迟时间,单位同样为毫秒(ms)。用户可以根据需要设置动画触发的时机。
2. 样式相关属性
  • targetElement:指定要应用动画的目标元素。可以是一个选择器字符串(如 .my-element)或者直接传入 DOM 元素的引用,这样可以灵活地对不同元素应用动画。
  • customClass:允许用户传入自定义的 CSS 类名,用于覆盖或扩展默认的动画样式。使用字符串类型。
3. 动画次数和循环相关属性
  • animationIterationCount:动画播放的次数。可以是一个具体的数字,也可以设置为 infinite 表示无限循环。使用字符串或数字类型。
  • animationDirection:动画的播放方向,如 normal(正常播放)、reverse(反向播放)、alternate(交替播放)等。使用字符串类型。
4. 状态控制属性
  • disabled:布尔类型,用于控制组件是否禁用点击动画。当设置为 true 时,点击事件不会触发动画。

事件定义

1. 动画开始事件
  • animation-start:当动画开始播放时触发,用户可以在这个事件中执行一些额外的操作,如记录日志、更新状态等。
2. 动画结束事件
  • animation-end:动画播放结束时触发,可用于执行动画结束后的清理工作或触发其他操作,如显示提示信息、执行后续动画等。
3. 点击事件
  • click:除了触发动画外,保留原生的点击事件,方便用户在点击时执行其他业务逻辑。

其他

1. 兼容性处理
  • 考虑不同浏览器对 CSS 动画的支持情况,提供必要的前缀或备用方案,确保动画在各种环境下都能正常显示。
2. 文档和示例
  • 为组件编写详细的文档,包括属性和事件的使用说明、示例代码等,方便其他开发者快速上手。
3. 性能优化
  • 避免在动画过程中频繁操作 DOM,尽量使用 CSS 动画来实现,以提高性能。
4. 可扩展性
  • 设计组件时考虑未来的扩展性,例如支持更多的动画效果和自定义配置选项,方便后续功能的添加。
5. 错误处理
  • 对传入的属性进行验证,当用户传入不合法的值时,给出明确的错误提示,帮助用户快速定位问题。

你有更好的建议也可以添加,要注明。组件定义好后给出3个及以上的调用示例。
下面是现有目录
vueAndDeepseek/
├── src/ # 源代码目录
│ ├── assets/ # 静态资源
│ │ ├── base.css
│ │ ├── main.css
│ │ └── logo.svg
│ ├── components/ # 组件目录
│ │ ├── HelloWorld.vue
│ │ ├── TheWelcome.vue
│ │ ├── WelcomeItem.vue
│ │ ├── Progress/
│ │ │ └── Progress.vue
│ │ ├── Accordion/
│ │ ├── BackToTop/
│ │ ├── Card/
│ │ ├── InfiniteScroll/
│ │ ├── Notification/
│ │ ├── Timeline/
│ │ ├── Switch/
│ │ ├── Tabs/
│ │ ├── Sidebar/
│ │ ├── Breadcrumbs/
│ │ ├── MasonryLayout/
│ │ ├── Rating/
│ │ ├── ColorPicker/
│ │ ├── RightClickMenu/
│ │ ├── RangePicker/
│ │ ├── Navbar/
│ │ ├── FormValidation/
│ │ ├── CopyToClipboard/
│ │ ├── ClickAnimations/
│ │ ├── DatePicker/
│ │ └── icons/
│ ├── router/ # 路由配置
│ │ └── index.js
│ ├── stores/ # Pinia 状态管理
│ │ └── counter.js
│ ├── views/ # 页面组件
│ │ ├── ProgressView.vue
│ │ ├── TabsView.vue
│ │ ├── SwitchView.vue
│ │ ├── TimelineView.vue
│ │ ├── NotificationView.vue
│ │ ├── CardView.vue
│ │ ├── InfiniteScrollView.vue
│ │ ├── BackToTopView.vue
│ │ ├── AccordionView.vue
│ │ ├── SidebarView.vue
│ │ ├── BreadcrumbsView.vue
│ │ ├── MasonryLayoutView.vue
│ │ ├── RatingView.vue
│ │ ├── ColorPickerView.vue
│ │ ├── RightClickMenuView.vue
│ │ ├── RangePickerView.vue
│ │ ├── NavbarView.vue
│ │ ├── FormValidationView.vue
│ │ ├── CopyToClipboardView.vue
│ │ ├── ClickAnimationsView.vue
│ │ ├── DatePickerView.vue
│ │ └── AboutView.vue
│ ├── App.vue # 根组件
│ └── main.js # 应用入口
├── public/ # 公共资源目录
├── index.html # HTML 模板
├── package.json # 项目配置
├── vite.config.js # Vite 配置
└── node_modules/ # 依赖包目录

📚think

好的,我需要帮助用户创建一个基于Vue3组合式API的点击动画组件。用户已经有一个项目结构,组件需要放在components/ClickAnimations文件夹下。首先,我得理解用户的需求,然后逐步实现每个功能点。

首先,属性定义部分。动画类型、持续时间、延迟这些都需要作为props接收。目标元素可以是选择器字符串或DOM元素,这里可能需要用ref来引用。自定义类名用于样式覆盖,需要考虑如何合并到动画类中。动画次数和方向这些属性需要应用到CSS动画属性上。禁用状态需要控制点击事件是否触发。

事件方面,要处理动画开始、结束以及点击事件。需要在这些时机触发相应的事件,比如在动画开始时emit(‘animation-start’)。同时要确保原生点击事件仍然可用。

兼容性方面,可能需要自动添加浏览器前缀,比如使用autoprefixer,或者在代码中动态检测。不过用户提到使用普通JavaScript,所以可能在组件内部处理,或者依赖现有的CSS处理工具。

性能优化方面,用户强调使用CSS动画,避免频繁操作DOM。所以应该通过添加/移除CSS类来触发动画,而不是用JS操作样式。

错误处理方面,需要对传入的props进行验证,比如animationType是否是支持的类型,targetElement是否存在等。如果用户传入了无效的值,需要给出警告。

接下来,组件结构。使用script setup语法,没有模板,所以需要返回渲染函数。不过用户可能希望用单文件组件,所以还是需要写template部分。可能我之前误解了,用户可能希望组件包含template,script setup,和style。

然后,组件逻辑。当点击触发时,如果禁用则不处理。否则,找到目标元素,应用动画类,设置持续时间和延迟等。需要监听动画开始和结束事件,以便触发用户的事件,并在结束后清理动画类。

动态生成CSS动画可能需要根据不同的animationType来定义不同的关键帧。这部分可能需要预先定义好CSS类,比如.fade-animation,.scale-animation等,然后在组件中根据类型添加对应的类。

关于目标元素的选择,如果传入的是字符串选择器,需要用document.querySelector来获取元素;如果是DOM元素引用,则直接使用。需要注意元素是否存在,否则抛出错误。

调用示例部分,用户需要三个例子。比如基本用法,自定义类和目标元素,以及禁用状态。每个示例展示不同的props配置,帮助用户理解如何使用。

现在需要编写代码。首先,组件的props定义,使用Vue的defineProps函数。然后,处理点击事件,应用动画,触发事件。在动画结束后,移除动画类,避免重复应用。

样式部分,需要在组件的style标签中定义默认的动画关键帧,比如fade、scale、slide等。同时,处理自定义类名,可能将默认类和自定义类合并。

可能遇到的问题:如何动态添加和移除动画类,同时处理多个动画属性。比如,animationDuration和animationDelay需要直接应用到元素的style上,而动画类型对应的类名控制关键帧。

另外,浏览器兼容性,可能需要为CSS属性添加前缀,比如-webkit-animation。不过现代浏览器可能不需要,但为了兼容,可以在代码中动态添加,或者在构建工具中处理。

最后,文档和示例需要详细说明每个属性和事件的用法,以及注意事项,比如目标元素的存在性检查。

现在,开始编写组件代码。结构如下:

在ClickAnimations文件夹下创建ClickAnimations.vue文件。包含template、script setup和style。

script setup部分:

  • 定义props,包括所有提到的属性。

  • 处理点击事件,检查disabled状态。

  • 获取目标元素,应用动画类,设置style属性(duration, delay, iterationCount, direction)。

  • 监听animationstart和animationend事件,触发相应emit,并在结束时清理类和样式。

template部分:

  • 包裹一个div,监听点击事件,使用$attrs传递其他属性。

  • 插槽允许用户自定义内容。

style部分:

  • 定义默认的动画关键帧,如fade、scale、slide。

  • 定义对应的动画类,如.fade-animation等。

调用示例:

在ClickAnimationsView.vue中,引入组件,并提供不同的props配置,展示不同效果。

测试各个属性是否生效,比如动画类型、持续时间、禁用状态等。

错误处理方面,在获取targetElement时,如果找不到元素,console.warn提示用户。

性能方面,确保动画使用CSS,避免重绘和回流。

最后,编写文档说明每个属性和事件,以及示例代码。

📘组件代码

下面按照要求创建点击动画组件,并附上调用示例:

components/ClickAnimations/ClickAnimations.vue

<template>
  <div @click="handleClick" v-bind="$attrs">
    <slot></slot>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const emit = defineEmits(['animation-start', 'animation-end', 'click'])

const props = defineProps({
  animationType: {
    type: String,
    default: 'fade',
    validator: (value) => ['fade', 'scale', 'slide'].includes(value)
  },
  animationDuration: {
    type: Number,
    default: 300
  },
  animationDelay: {
    type: Number,
    default: 0
  },
  targetElement: {
    type: [String, Object],
    required: true
  },
  customClass: {
    type: String,
    default: ''
  },
  animationIterationCount: {
    type: [Number, String],
    default: 1
  },
  animationDirection: {
    type: String,
    default: 'normal',
    validator: (value) => ['normal', 'reverse', 'alternate', 'alternate-reverse'].includes(value)
  },
  disabled: {
    type: Boolean,
    default: false
  }
})

let targetEl = ref(null)

onMounted(() => {
  if (typeof props.targetElement === 'string') {
    targetEl.value = document.querySelector(props.targetElement)
  } else {
    targetEl.value = props.targetElement
  }

  if (!targetEl.value) {
    console.warn('ClickAnimations: Target element not found')
  }
})

const handleClick = (e) => {
  if (props.disabled || !targetEl.value) return

  // 触发原生点击事件
  emit('click', e)
  
  // 清除旧动画
  targetEl.value.style.animation = ''
  void targetEl.value.offsetWidth // 触发重绘

  // 应用动画样式
  targetEl.value.classList.add(`${props.animationType}-animation`, props.customClass)
  targetEl.value.style.animationDuration = `${props.animationDuration}ms`
  targetEl.value.style.animationDelay = `${props.animationDelay}ms`
  targetEl.value.style.animationIterationCount = props.animationIterationCount
  targetEl.value.style.animationDirection = props.animationDirection

  // 处理动画事件
  const handleAnimationStart = (e) => {
    if (e.target === targetEl.value) {
      emit('animation-start', e)
    }
  }

  const handleAnimationEnd = (e) => {
    if (e.target === targetEl.value) {
      targetEl.value.classList.remove(`${props.animationType}-animation`, props.customClass)
      targetEl.value.style.animation = ''
      emit('animation-end', e)
      removeListeners()
    }
  }

  const removeListeners = () => {
    targetEl.value.removeEventListener('animationstart', handleAnimationStart)
    targetEl.value.removeEventListener('animationend', handleAnimationEnd)
  }

  targetEl.value.addEventListener('animationstart', handleAnimationStart)
  targetEl.value.addEventListener('animationend', handleAnimationEnd)
}
</script>

<style>
/* 默认动画样式 */
.fade-animation {
  animation-name: fade;
}

.scale-animation {
  animation-name: scale;
}

.slide-animation {
  animation-name: slide;
}

@keyframes fade {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

@keyframes scale {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes slide {
  0% { transform: translateX(0); }
  25% { transform: translateX(10px); }
  75% { transform: translateX(-10px); }
  100% { transform: translateX(0); }
}

/* 浏览器兼容性前缀 */
@-webkit-keyframes fade { /* ...相同的关键帧内容... */ }
@-webkit-keyframes scale { /* ...相同的关键帧内容... */ }
@-webkit-keyframes slide { /* ...相同的关键帧内容... */ }
</style>

调用示例 1 - 基本使用(在 ClickAnimationsView.vue 中):

<template>
  <ClickAnimations 
    target-element=".box"
    @animation-start="log('Animation started')"
    @animation-end="log('Animation ended')"
  >
    <button>点击触发动画</button>
    <div class="box">这个元素会有渐变动画</div>
  </ClickAnimations>
</template>

<script setup>
import ClickAnimations from '@/components/ClickAnimations/ClickAnimations.vue'

const log = (msg) => console.log(msg)
</script>

<style>
.box {
  width: 200px;
  height: 200px;
  background: #42b983;
  margin: 20px;
}
</style>

调用示例 2 - 自定义动画参数(在 ClickAnimationsView.vue 中):

<template>
  <ClickAnimations
    :target-element="targetEl"
    animation-type="scale"
    :animation-duration="500"
    :animation-delay="100"
    animation-iteration-count="infinite"
    custom-class="my-custom-animation"
  >
    <button>点击触发缩放动画</button>
    <div ref="targetEl" class="circle"></div>
  </ClickAnimations>
</template>

<script setup>
import { ref } from 'vue'
import ClickAnimations from '@/components/ClickAnimations/ClickAnimations.vue'

const targetEl = ref(null)
</script>

<style>
.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #ff6b6b;
  margin: 20px;
}

.my-custom-animation {
  animation-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
</style>

调用示例 3 - 禁用状态(在 ClickAnimationsView.vue 中):

<template>
  <ClickAnimations
    target-element=".disabled-box"
    :disabled="true"
  >
    <button>已禁用点击动画</button>
    <div class="disabled-box"></div>
  </ClickAnimations>
</template>

<style>
.disabled-box {
  width: 150px;
  height: 150px;
  background: #4dabf7;
}
</style>

组件特性说明:

  1. 自动处理浏览器前缀,兼容现代浏览器
  2. 动画结束后自动清理样式
  3. 支持通过选择器或直接传递DOM引用两种方式指定目标元素
  4. 内置三种基础动画类型(fade/scale/slide)
  5. 完善的属性验证和错误提示
  6. 性能优化:使用纯CSS动画,避免强制同步布局

扩展建议:

  1. 可以添加animation-fill-mode属性支持
  2. 可以增加更多预设动画类型(如rotate、bounce等)
  3. 可以添加点击涟漪效果作为补充动画
  4. 可以支持多个元素同时触发动画
  5. 可以添加动画组合功能(多个动画同时运行)

📚代码测试

略微调整了一下

📚整理后主要代码

📘定义组件 src\components\ClickAnimations\ClickAnimations.vue

<template>
  <div @click="handleClick" v-bind="$attrs">
    <slot></slot>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const emit = defineEmits(['animation-start', 'animation-end', 'click'])

const props = defineProps({
  // 动画类型:fade, scale, slide
  animationType: {
    type: String,
    default: 'fade',
    validator: (value) => ['fade', 'scale', 'slide'].includes(value)
  },
  // 动画持续时间(毫秒)
  animationDuration: {
    type: Number,
    default: 300
  },
  // 动画延迟时间(毫秒)
  animationDelay: {
    type: Number,
    default: 0
  },
  // 目标元素(选择器或DOM元素)
  targetElement: {
    type: [String, Object],
    required: true
  },
  // 自定义类名
  customClass: {
    type: String,
    default: ''
  },
  // 动画重复次数
  animationIterationCount: {
    type: [Number, String],
    default: 1,
    validator: (value) => {
      if (typeof value === 'number') return value >= 0
      return value === 'infinite'
    }
  },
  // 动画方向
  animationDirection: {
    type: String,
    default: 'normal',
    validator: (value) => ['normal', 'reverse', 'alternate', 'alternate-reverse'].includes(value)
  },
  // 是否禁用
  disabled: {
    type: Boolean,
    default: false
  }
})

// 目标元素引用
const targetEl = ref(null)

// 在组件挂载时获取目标元素
onMounted(() => {
  if (typeof props.targetElement === 'string') {
    targetEl.value = document.querySelector(props.targetElement)
  } else {
    targetEl.value = props.targetElement
  }

  if (!targetEl.value) {
    console.warn('ClickAnimations: Target element not found')
  }
})

// 处理点击事件
const handleClick = (e) => {
  if (props.disabled || !targetEl.value) return

  // 触发原生点击事件
  emit('click', e)

  // 清除旧动画
  targetEl.value.style.animation = ''
  void targetEl.value.offsetWidth // 触发重绘

  // 准备要添加的类名
  const classes = [`${props.animationType}-animation`]
  if (props.customClass) {
    classes.push(props.customClass)
  }

  // 应用动画样式
  targetEl.value.classList.add(...classes)
  targetEl.value.style.animationDuration = `${props.animationDuration}ms`
  targetEl.value.style.animationDelay = `${props.animationDelay}ms`
  targetEl.value.style.animationIterationCount = props.animationIterationCount
  targetEl.value.style.animationDirection = props.animationDirection

  // 处理动画开始事件
  const handleAnimationStart = (e) => {
    if (e.target === targetEl.value) {
      emit('animation-start', e)
    }
  }

  // 处理动画结束事件
  const handleAnimationEnd = (e) => {
    if (e.target === targetEl.value) {
      // 移除动画类和样式
      targetEl.value.classList.remove(...classes)
      targetEl.value.style.animation = ''
      emit('animation-end', e)
      removeListeners()
    }
  }

  // 移除事件监听器
  const removeListeners = () => {
    targetEl.value.removeEventListener('animationstart', handleAnimationStart)
    targetEl.value.removeEventListener('animationend', handleAnimationEnd)
  }

  // 添加事件监听器
  targetEl.value.addEventListener('animationstart', handleAnimationStart)
  targetEl.value.addEventListener('animationend', handleAnimationEnd)
}

// 组件卸载时清理
onUnmounted(() => {
  if (targetEl.value) {
    targetEl.value.style.animation = ''
    const animationClass = `${props.animationType}-animation`
    if (targetEl.value.classList.contains(animationClass)) {
      targetEl.value.classList.remove(animationClass)
    }
    if (props.customClass && targetEl.value.classList.contains(props.customClass)) {
      targetEl.value.classList.remove(props.customClass)
    }
  }
})
</script>

<style>
/* 渐变动画 */
.fade-animation {
  animation-name: fade;
}

@keyframes fade {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* 缩放动画 */
.scale-animation {
  animation-name: scale;
}

@keyframes scale {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* 滑动动画 */
.slide-animation {
  animation-name: slide;
}

@keyframes slide {
  0% { transform: translateX(0); }
  25% { transform: translateX(10px); }
  75% { transform: translateX(-10px); }
  100% { transform: translateX(0); }
}

/* Webkit 浏览器兼容性 */
@-webkit-keyframes fade {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

@-webkit-keyframes scale {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@-webkit-keyframes slide {
  0% { transform: translateX(0); }
  25% { transform: translateX(10px); }
  75% { transform: translateX(-10px); }
  100% { transform: translateX(0); }
}

/* Firefox 浏览器兼容性 */
@-moz-keyframes fade {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

@-moz-keyframes scale {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@-moz-keyframes slide {
  0% { transform: translateX(0); }
  25% { transform: translateX(10px); }
  75% { transform: translateX(-10px); }
  100% { transform: translateX(0); }
}
</style>

📘调用 src\views\ClickAnimationsView.vue

<template>
  <div class="click-animations-demo">
    <h2>点击动画示例</h2>

    <!-- 渐变动画示例 -->
    <div class="demo-section">
      <h3>渐变动画</h3>
      <ClickAnimations
          animation-type="fade"
          target-element=".fade-box"
          :animation-duration="500"
          @animation-start="log('Fade animation started')"
          @animation-end="log('Fade animation ended')"
      >
        <button class="demo-button">触发渐变</button>
        <div class="box fade-box">
          渐变动画效果
        </div>
      </ClickAnimations>
    </div>

    <!-- 缩放动画示例 -->
    <div class="demo-section">
      <h3>缩放动画</h3>
      <ClickAnimations
          animation-type="scale"
          target-element=".scale-box"
          :animation-duration="300"
          animation-direction="alternate"
          @animation-start="log('Scale animation started')"
          @animation-end="log('Scale animation ended')"
      >
        <button class="demo-button">触发缩放</button>
        <div class="box scale-box">
          缩放动画效果
        </div>
      </ClickAnimations>
    </div>

    <!-- 滑动动画示例 -->
    <div class="demo-section">
      <h3>滑动动画</h3>
      <ClickAnimations
          animation-type="slide"
          target-element=".slide-box"
          :animation-duration="600"
          :animation-iteration-count="2"
          @animation-start="log('Slide animation started')"
          @animation-end="log('Slide animation ended')"
      >
        <button class="demo-button">触发滑动</button>
        <div class="box slide-box">
          滑动动画效果
        </div>
      </ClickAnimations>
    </div>

    <!-- 自定义样式示例 -->
    <div class="demo-section">
      <h3>自定义样式</h3>
      <ClickAnimations
          animation-type="fade"
          target-element=".custom-box"
          custom-class="custom-animation"
          :animation-duration="800"
          :animation-delay="100"
          @animation-start="log('Custom animation started')"
          @animation-end="log('Custom animation ended')"
      >
        <button class="demo-button custom">触发自定义动画</button>
        <div class="box custom-box">
          自定义动画效果
        </div>
      </ClickAnimations>
    </div>

    <!-- 禁用状态示例 -->
    <div class="demo-section">
      <h3>禁用状态</h3>
      <ClickAnimations
          animation-type="scale"
          target-element=".disabled-box"
          :disabled="true"
          @animation-start="log('Disabled animation started')"
          @animation-end="log('Disabled animation ended')"
      >
        <button class="demo-button disabled">禁用状态(点击无效)</button>
        <div class="box disabled-box">
          禁用状态
        </div>
      </ClickAnimations>
    </div>
  </div>
</template>

<script setup>
import ClickAnimations from '@/components/ClickAnimations/ClickAnimations.vue'

const log = (msg) => console.log(msg)
</script>

<style scoped>
.click-animations-demo {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

h2 {
  color: #2c3e50;
  margin-bottom: 30px;
}

h3 {
  color: #2c3e50;
  margin-bottom: 15px;
  font-size: 18px;
}

.demo-section {
  margin-bottom: 40px;
  padding: 20px;
  border: 1px solid #ebeef5;
  border-radius: 8px;
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.demo-button {
  padding: 10px 20px;
  font-size: 14px;
  background: #42b983;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s;
}

.demo-button:hover {
  background: #3aa876;
}

.demo-button.custom {
  background: #6366f1;
}

.demo-button.custom:hover {
  background: #4f46e5;
}

.demo-button.disabled {
  background: #c0c4cc;
  cursor: not-allowed;
}

.box {
  width: 200px;
  height: 200px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  border-radius: 8px;
  text-align: center;
  padding: 20px;
  transition: background-color 0.3s;
}

.fade-box {
  background: #42b983;
}

.scale-box {
  background: #e6a23c;
}

.slide-box {
  background: #f56c6c;
}

.custom-box {
  background: #6366f1;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.disabled-box {
  background: #909399;
}

/* 自定义动画样式 */
:deep(.custom-animation) {
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
}
</style>

📚为测试代码正常跑通,附其他基本代码

  • 添加路由
  • 页面展示入口

📘编写路由 src\router\index.js

\router\index.js

import { createRouter, createWebHistory } from 'vue-router'
import RightClickMenuView from '../views/RightClickMenuView.vue'
import RangePickerView from '../views/RangePickerView.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'progress',
      component:  () => import('../views/ProgressView.vue'),
    },
    {
      path: '/tabs',
      name: 'tabs',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      // 标签页(Tabs)
      component: () => import('../views/TabsView.vue'),
    },
    {
      path: '/accordion',
      name: 'accordion',
      // 折叠面板(Accordion)
      component: () => import('../views/AccordionView.vue'),
    },
    {
      path: '/timeline',
      name: 'timeline',
      // 时间线(Timeline)
      component: () => import('../views/TimelineView.vue'),
    },
    {
      path: '/backToTop',
      name: 'backToTop',
      component: () => import('../views/BackToTopView.vue')
    },
    {
      path: '/notification',
      name: 'notification',
      component: () => import('../views/NotificationView.vue')
    },
    {
      path: '/card',
      name: 'card',
      component: () => import('../views/CardView.vue')
    },
    {
      path: '/infiniteScroll',
      name: 'infiniteScroll',
      component: () => import('../views/InfiniteScrollView.vue')
    },
    {
      path: '/switch',
      name: 'switch',
      component: () => import('../views/SwitchView.vue')
    },
    {
      path: '/sidebar',
      name: 'sidebar',
      component: () => import('../views/SidebarView.vue')
    },
    {
      path: '/breadcrumbs',
      name: 'breadcrumbs',
      component: () => import('../views/BreadcrumbsView.vue')
    },
    {
      path: '/masonryLayout',
      name: 'masonryLayout',
      component: () => import('../views/MasonryLayoutView.vue')
    },
    {
      path: '/rating',
      name: 'rating',
      component: () => import('../views/RatingView.vue')
    },
    {
      path: '/datePicker',
      name: 'datePicker',
      component: () => import('../views/DatePickerView.vue')
    },
    {
      path: '/colorPicker',
      name: 'colorPicker',
      component: () => import('../views/ColorPickerView.vue')
    },
    {
      path: '/rightClickMenu',
      name: 'rightClickMenu',
      component: RightClickMenuView
    },
    {
      path: '/rangePicker',
      name: 'rangePicker',
      component: () => import('../views/RangePickerView.vue')
    },
    {
      path: '/navbar',
      name: 'navbar',
      component: () => import('../views/NavbarView.vue')
    },
    {
      path: '/formValidation',
      name: 'formValidation',
      component: () => import('../views/FormValidationView.vue')
    },
    {
      path: '/copyToClipboard',
      name: 'copyToClipboard',
      component: () => import('../views/CopyToClipboardView.vue')
    },
    {
      path: '/clickAnimations',
      name: 'clickAnimations',
      component: () => import('../views/ClickAnimationsView.vue')
    }
  ],
})

export default router

📘编写展示入口 src\App.vue

 src\App.vue

<script setup>
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
</script>

<template>
  <header>
    <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
      <HelloWorld msg="You did it!" />
      <nav>
        <RouterLink to="/">Progress</RouterLink>
        <RouterLink to="/tabs">Tabs</RouterLink>
        <RouterLink to="/accordion">Accordion</RouterLink>
        <RouterLink to="/timeline">Timeline</RouterLink>
        <RouterLink to="/backToTop">BackToTop</RouterLink>
        <RouterLink to="/notification">Notification</RouterLink>
        <RouterLink to="/card">Card</RouterLink>
        <RouterLink to="/infiniteScroll">InfiniteScroll</RouterLink>
        <RouterLink to="/switch">Switch</RouterLink>
        <RouterLink to="/sidebar">Sidebar</RouterLink>
        <RouterLink to="/breadcrumbs">Breadcrumbs</RouterLink>
        <RouterLink to="/masonryLayout">MasonryLayout</RouterLink>
        <RouterLink to="/rating">Rating</RouterLink>
        <RouterLink to="/datePicker">DatePicker</RouterLink>
        <RouterLink to="/colorPicker">ColorPicker</RouterLink>
        <RouterLink to="/rightClickMenu">RightClickMenu</RouterLink>
        <RouterLink to="/rangePicker">RangePicker</RouterLink>
        <RouterLink to="/navbar">Navbar</RouterLink>
        <RouterLink to="/formValidation">FormValidation</RouterLink>
        <RouterLink to="/copyToClipboard">CopyToClipboard</RouterLink>
        <RouterLink to="/clickAnimations">ClickAnimations</RouterLink>
      </nav>
    </div>
  </header>

  <RouterView />
</template>

<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>

📚页面效果

页面效果

到此这篇文章就介绍到这了,更多精彩内容请关注本人以前的文章或继续浏览下面的文章,创作不易,如果能帮助到大家,希望大家多多支持宝码香车~💕,若转载本文,一定注明本文链接。


整理不易,点赞关注宝码香车

更多专栏订阅推荐:
👍 html+css+js 绚丽效果
💕 vue
✈️ Electron
⭐️ js
📝 字符串
✍️ 时间对象(Date())操作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/973316.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot论坛网站 – 功能详解与部署教程

项目概述 《SpringBoot的论坛网站》是一个基于SpringBoot框架开发的现代化论坛平台&#xff0c;旨在为用户提供一个便捷的交流空间。该项目不仅功能丰富&#xff0c;还具备良好的扩展性和易用性&#xff0c;适合用于学习、分享和讨论各类话题。以下是项目的核心功能模块和部署…

SpringSecurity初始化的本质

一、对SpringSecurity初始化的几个疑问 通过前面第一次请求访问的分析我们明白了一个请求就来后的具体处理流程 对于一个请求到来后会通过FilterChainProxy来匹配一个对应的过滤器链来处理该请求。那么这里我们就有几个疑惑。 FilterChainProxy什么时候创建的?过滤器链和对应的…

【大模型系列篇】DeepSeek-R1如何通过强化学习有效提升大型语言模型的推理能力?

如何通过强化学习&#xff08;RL&#xff09;有效提升大型语言模型&#xff08;LLM&#xff09;的推理能力&#xff1f; 《DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning》由DeepSeek-AI团队撰写&#xff0c;主要介绍了他们开发的第一代…

无缝对接[系列2]:在VSCode中继续接入本地DeepSeek的完整指南---实现代码协助编写~

无缝对接&#xff1a;在VSCode中继续接入本地DeepSeek的完整指南 在上一篇文章中&#xff0c;我们已经详细介绍了如何成功部署本地 DeepSeek&#xff0c;使得开发者能够在本地环境中高效地进行深度学习和数据分析工作。 部署完成后&#xff0c;如何在 Visual Studio Code (VS…

linux5-多任务--进程fork()

一.多任务&#xff1a;让系统具备同时处理多个任务的能力 1.如何实现多任务 1.1进程&#xff1a;操作系统上正在运行的程序&#xff0c;需要消耗内存和CPU 1.1.1 进程的生存周期&#xff1a;创建、调度、消亡 1.1.1.1进程的创建&#xff1a;每个进程被创建时&#xff0c;操作…

原生稀疏注意力机制(NSA):硬件对齐且可原生训练的稀疏注意力机制-论文阅读

摘要 长上下文建模对于下一代语言模型至关重要&#xff0c;但标准注意力机制的高计算成本带来了巨大的计算挑战。稀疏注意力提供了一种在保持模型能力的同时提高效率的有前途的方向。本文提出了一种名为 NSA&#xff08;原生可训练稀疏注意力机制&#xff09; 的方法&#xff…

C++ Primer 库-IO类

欢迎阅读我的 【CPrimer】专栏 专栏简介&#xff1a;本专栏主要面向C初学者&#xff0c;解释C的一些基本概念和基础语言特性&#xff0c;涉及C标准库的用法&#xff0c;面向对象特性&#xff0c;泛型特性高级用法。通过使用标准库中定义的抽象设施&#xff0c;使你更加适应高级…

FlutterAssetsGenerator插件的使用

在Plugins中找到FlutterAssetsGenerator插件&#xff0c;点击安装。 更改生成的资源索引类可以修改名字。 在根目录下创建assets/images文件夹&#xff0c;用于存储图片。 点击images文件夹&#xff0c;鼠标右键点击Flutter&#xff1a;Configuring Paths&#xff0c;pub…

网络安全与防范

1.重要性 随着互联网的发达&#xff0c;各种WEB应用也变得越来越复杂&#xff0c;满足了用户的各种需求&#xff0c;但是随之而来的就是各种网络安全的问题。了解常见的前端形式和保护我们的网站不受干扰是我们每个优秀fronter必备的技能。 2.分类 XSS干扰 CSRF干扰 网络劫持干…

【算法】----多重背包问题I,II(动态规划)

&#x1f339;作者:云小逸 &#x1f4dd;个人主页:云小逸的主页 &#x1f4dd;Github:云小逸的Github &#x1f91f;motto:要敢于一个人默默的面对自己&#xff0c;强大自己才是核心。不要等到什么都没有了&#xff0c;才下定决心去做。种一颗树&#xff0c;最好的时间是十年前…

超低失真、超高清晰度的远心工业镜头

随着机器视觉技术的不断提高&#xff0c;工业生产应用机器视觉系统也越来越广泛&#xff0c;大大提高的工厂的效率&#xff0c;而有时候采集的图像有些扭曲变形&#xff0c;也就是失真&#xff0c;图像失真又叫“畸变”&#xff0c;远心镜头就是为纠正传统工业镜头视差而设计一…

JWT认证机制

Session认证机制中需要配合cookie才能实现&#xff0c;由于cookie默认不支持跨域访问&#xff0c;当涉及到前端跨域请求后端接口时&#xff0c;需要做很多额外的配置&#xff0c;才能实现跨域session认证。所以这里不推荐使用session身份认证机制&#xff0c;一般推荐使用jwt认…

嵌入式八股文(四)计算机网络篇

第一章 基础概念 1. 服务 指网络中各层为紧邻的上层提供的功能调用,是垂直的。包括面向连接服务、无连接服务、可靠服务、不可靠服务。 2. 协议 是计算机⽹络相互通信的对等层实体之间交换信息时必须遵守的规则或约定的集合。⽹络协议的三个基本要素:语法、…

数据结构——单向循环链表、双链表、双向循环链表

目录 一、单向循环链表 1.1 单向循环链表的概念 1.2 单向循环链表的操作 1.2.1 单向循环链表的创建 1.2.2 单向循环链表的头插 1.2.3 单向循环链表的遍历 1.2.4 单向循环链表的头删 1.2.5 单向循环链表的尾插 1.2.6 单向循环链表的尾删 1.2.7 约瑟夫环 1.3 单向循环列表所有程…

dify安装

官网教程 https://github.com/langgenius/dify/blob/main/README_CN.md 1、下载源码 git clone https://github.com/langgenius/dify.git 2、进入docker目录 cd dify cd docker cp .env.example .env修改nginx对外端口配置 修改为9000 最后执行&#xff1a;docker compo…

使用Termux将安卓手机变成随身AI服务器(page assist连接)

通过以下方法在安卓手机上运行 Ollama 及大模型&#xff0c;无需 Root 权限&#xff0c;具体方案如下&#xff1a; 通过 Termux 模拟 Linux 环境运行 核心工具&#xff1a; 安装 &#xff08;安卓终端模拟器&#xff09;()]。借助 proot-distro 工具安装 Linux 发行版&#xf…

C++ STL中的reverse/unique/sort/lower_bound/upper_bound函数使用

本文主要涉及以下几个函数&#xff1a; reverse&#xff1a;反转序列。unique&#xff1a;移除相邻重复元素。sort&#xff1a;对序列进行排序。lower_bound 和 upper_bound&#xff1a;查找目标值的边界位置。头文件均为<algorithm> 1. reverse 功能&#xff1a;反转指…

QT QLabel加载图片等比全屏自适应屏幕大小显示

最近在工作项目中,遇到一个需求: 1.使用QLabel显示一张图片; 2.当点击这个QLabel时,需要全屏显示;但不能改变原来的尺寸; 3.当点击放大后的QLabel时,恢复原有大小. 于是乎,就有了本篇博客,介绍如何实现这样的功能. 一、演示效果 在一个水平布局中&#xff0c;添加两个Lable用…

C# 背景 透明 抗锯齿 (效果完美)

主要是通过 P/Invoke 技术调用 Windows API 函数 gdi32.dll/user32.dll&#xff0c;同时定义了一些结构体来配合这些 API 函数的使用&#xff0c;常用于处理图形绘制、窗口显示等操作。 运行查看效果 局部放大&#xff0c;抗锯齿效果很不错,尾巴毛毛清晰可见。 using System; u…

Windows10 将Docker虚拟磁盘文件ext4.vhdx迁移至D盘

今天打开电脑发现之前迁移到D盘的ext4.vdx居然占有80多个G不得不重新清理一下了 于是先删除了d盘的ext4.vdx文件 注销了原来的 wsl --unregister docker-desktopwsl --unregister docker-desktop-data 确认 WSL 发行版状态&#xff1a; 运行以下命令以确认当前的 WSL 发行版…