欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3封裝一個(gè)帶動(dòng)畫(huà)的關(guān)閉按鈕示例詳解

 更新時(shí)間:2023年09月28日 09:06:10   作者:jsoncode  
這篇文章主要為大家介紹了vue3封裝一個(gè)帶動(dòng)畫(huà)的關(guān)閉按鈕示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

預(yù)覽效果

實(shí)現(xiàn)源碼

<template>
  <MenuBtn
      :open="openMenu"
      :size="24"
  />
</template>
<template>
  <div :class="`menu ${open?'open':''}`" :style="`width:${size}px;height:${size}px`">
    <span
        :style="`
          transition-duration:${duration}ms;
          transform:${open?`translateY(${(size-2)/2}px) rotate(-45deg)`:`translateY(${size/6}px)`};
        `"
    />
    <span
        :style="`
          transition-duration:${duration}ms;
          ${open?`opacity: 0;transform: rotate(-45deg)`:''}
        `"
    />
    <span
        :style="`
          transition-duration:${duration}ms;
          transform:${open?`translateY(${-(size-2)/2}px) rotate(45deg)`:`translateY(-${size/6}px)`};
        `"
    />
  </div>
</template>
<script setup>
// 這里用了vue3的專用寫(xiě)法。vue2寫(xiě)法,自行實(shí)現(xiàn)。
const {open, size, duration} = defineProps({
  open: {
    type: Boolean,
    default: false,
    required: true,
  },
  size: {
    type: Number,
    default: 24,
    required: false
  },
  duration: {
    type: Number,
    default: 300,
    required: false
  }
});
</script>
<style scoped lang="scss">
.menu {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  span {
    height: 2px;
    border-radius: 2px;
    display: flex;
    width: 100%;
    background-color: #333;
  }
}
</style>

源碼說(shuō)明

帶有變量的樣式,都寫(xiě)在行內(nèi)了,因?yàn)檫@樣適合用在任意場(chǎng)景下。

// nuxt3 
npx nuxi init <project-name>
// nuxt2
yarn create nuxt-app <project-name>
// vue-cli
vue create <project-name>
// vite
npm init vite-app <project-name>

其他場(chǎng)景

vite可以直接在style標(biāo)簽中使用js變量

npm init vite-app <project-name>
<template>
  <h1>{color}</h1>
</template>
<script>
export default {
  data () {
    return {
      color: 'red'
    }
  }
}
</script>
<style vars="{ color }" scoped>
h1 {
  color: var(--color);
}
</style>

以上就是vue3封裝一個(gè)帶動(dòng)畫(huà)的關(guān)閉按鈕示例詳解的詳細(xì)內(nèi)容,更多關(guān)于vue3封裝動(dòng)畫(huà)關(guān)閉按鈕的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Vue實(shí)現(xiàn)全局的toast組件方式

    Vue實(shí)現(xiàn)全局的toast組件方式

    這篇文章主要介紹了Vue實(shí)現(xiàn)全局的toast組件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Vue3.x最小原型系統(tǒng)講解

    Vue3.x最小原型系統(tǒng)講解

    這篇文章主要介紹了Vue3.x最小原型系統(tǒng)講解。既然用Vue3.0構(gòu)建最小原型系統(tǒng),那么肯定要用尤大的最新構(gòu)建工具Vite來(lái)進(jìn)行項(xiàng)目的初始化,下文舉例說(shuō)明,需要的朋友可以參考一下
    2022-02-02
  • element-plus+Vue3實(shí)現(xiàn)表格數(shù)據(jù)動(dòng)態(tài)渲染

    element-plus+Vue3實(shí)現(xiàn)表格數(shù)據(jù)動(dòng)態(tài)渲染

    在Vue中,el-table是element-ui提供的強(qiáng)大表格組件,可以用于展示靜態(tài)和動(dòng)態(tài)表格數(shù)據(jù),本文主要介紹了element-plus+Vue3實(shí)現(xiàn)表格數(shù)據(jù)動(dòng)態(tài)渲染,感興趣的可以了解一下
    2024-03-03
  • vue中使用v-if,v-else來(lái)設(shè)置css樣式的步驟

    vue中使用v-if,v-else來(lái)設(shè)置css樣式的步驟

    我們?cè)谑褂胿ue項(xiàng)目開(kāi)發(fā)時(shí),v-if是使用的非常多的,在這里我們談?wù)勅绾问褂胿-i來(lái)綁定修改css樣式,使用的主要是雙向數(shù)據(jù)綁定,即通過(guò)改變他的狀態(tài)來(lái)改變他的樣式,這篇文章主要介紹了vue中如何使用v-if,v-else來(lái)設(shè)置css樣式,需要的朋友可以參考下
    2023-03-03
  • Vue源碼學(xué)習(xí)之響應(yīng)式是如何實(shí)現(xiàn)的

    Vue源碼學(xué)習(xí)之響應(yīng)式是如何實(shí)現(xiàn)的

    最近接觸了vue.js,一度非常好奇vue.js是如何監(jiān)測(cè)數(shù)據(jù)更新并且重新渲染頁(yè)面,這篇文章主要給大家介紹了關(guān)于Vue源碼學(xué)習(xí)之響應(yīng)式是如何實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • VUE在for循環(huán)里面根據(jù)內(nèi)容值動(dòng)態(tài)的加入class值的方法

    VUE在for循環(huán)里面根據(jù)內(nèi)容值動(dòng)態(tài)的加入class值的方法

    這篇文章主要介紹了VUE在for循環(huán)里面根據(jù)內(nèi)容值動(dòng)態(tài)的加入class值的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-08-08
  • Vue中mapMutations傳遞參數(shù)方式

    Vue中mapMutations傳遞參數(shù)方式

    這篇文章主要介紹了Vue中mapMutations傳遞參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue router 跳轉(zhuǎn)后回到頂部的實(shí)例

    vue router 跳轉(zhuǎn)后回到頂部的實(shí)例

    今天小編就為大家分享一篇vue router 跳轉(zhuǎn)后回到頂部的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Vite?vue如何使用cdn引入element-plus

    Vite?vue如何使用cdn引入element-plus

    這篇文章主要介紹了Vite?vue使用cdn引入element-plus的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04
  • 詳解用vue.js和laravel實(shí)現(xiàn)微信授權(quán)登陸

    詳解用vue.js和laravel實(shí)現(xiàn)微信授權(quán)登陸

    本篇文章主要介紹了詳解用vue.js和laravel實(shí)現(xiàn)微信授權(quán)登陸,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06

最新評(píng)論