arshivbastian / vue

a teamwork for vue
0 stars 0 forks source link

Create Animated Menu #6

Open sdaliri opened 5 years ago

arshivbastian commented 5 years ago

we wanna create this menu : 2018-12-19_12-13-50

piece of cake ? maybe ...

first of all I have created this 3 icons :
allies | castel | war

now we need to add them instead of our router texts : ( I have created 3 routs Allies/Castel/War before for learning how check here )

html

<div id="nav">
      <div id="menu" :style="{'margin-bottom': state}">
        <sui-divider horizontal inverted id="menudivider" @click="menutoggle">Menu</sui-divider>
         <router-link to="/allies"> <img src="./assets/allies.png" /> </router-link> 
        <router-link to="/castel"> <img src="./assets/castel.png" /> </router-link>
        <router-link to="/war"> <img src="./assets/war.png" /> </router-link>
      </div>
    </div>

lets check this up :

script

<script>
export default {
  data () {
    return {
      state: '-145px'
    }
  },
  methods: {
    menutoggle () {
      if (this.state == '-145px') {
        this.state = '0px'
      }
      else if (this.state == '0px') {
        this.state = '-145px'
      }
    },
  }
}
</script>

this is most important part lets divide it :

data () {
    return {
      state: '-145px'
    }
  },

in this part we define state that is sat on menu-->style-->margin-bottom , so in first load 'margin-bottomof menu is -145 ( beneath body ) , after this we need to toggle menu'smargin-bottom` with 0 and -145 by clicking on menu divider

methods: {
    menutoggle () {
      if (this.state == '-145px') {
        this.state = '0px'
      }
      else if (this.state == '0px') {
        this.state = '-145px'
      }
    },
  }

the menutoggle function is calling by menu divider and each time check and change the state that is margin-bottom of the menu by that transition-duration: 2s; in CSS part menu toggle smoothly between margin-bottom = 0px and margin-bottom = -145px

piece of cake , wasn't it ?