Created
May 19, 2020 16:33
-
-
Save Musinux/1dc5704b6c8582f397b5bfebdfb5e6f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="hello"> | |
<button class="dropdown-printer" v-on:click="showTrucs">click me! </button> | |
<div ref="dropdown" id="dropdown" v-show="show" :style="styleDropdown()"> | |
<button v-for="item of items" :key="item">{{ item }}</button> | |
</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'HelloWorld', | |
data: () => { | |
return { | |
lastButtonClicked: null, | |
show: false, | |
items: ['machin', 'bidule', 'truc'] | |
} | |
}, | |
methods: { | |
showTrucs (evt) { | |
this.show = !this.show | |
this.lastButtonClicked = evt.target | |
}, | |
styleDropdown () { | |
if (!this.lastButtonClicked) return {} | |
const posFinal = this.lastButtonClicked.getBoundingClientRect() | |
const dropdown = this.$refs.dropdown | |
console.log('dropdown', dropdown) | |
console.log('posfinal', posFinal) | |
return { | |
top: (posFinal.y + posFinal.height) + 'px', | |
left: posFinal.x + 'px' | |
} | |
} | |
} | |
} | |
</script> | |
<!-- Add "scoped" attribute to limit CSS to this component only --> | |
<style scoped> | |
.dropdown-printer { | |
padding: 10px; | |
background-color: lightgreen; | |
border: 1px solid black; | |
} | |
#dropdown { | |
position: absolute; | |
width: 90px; | |
border: 1px solid black; | |
} | |
#dropdown button { | |
display: block; | |
} | |
</style> |
<button class="bouton" v-on:click ="createameliorer" >{{'AMELIORER'}}</button>
<div ref="defense" id="dropdown" v-show= "showdefense" :style="styleDropdown()" >
<button v-for="defense of defenses" :key="defense.id">{{defense.name}}</button>
</div>
</div>
</template>
<script>
export default {
name: "village",
data() {
return {
showdefense: false,
lastButtonCliked: null,
idplayer: 0,
pseudo: "null",
defenses:[
{id: 0,name: 'douve'},
{id: 1, name: 'tower'}
]
};
},
methods:{
createdefense(evt){
this.showdefense = !this.showdefense
this.lastButtonCliked = evt.target
},
styleDropdown () {
if (!this.lastButtonClicked) return {}
const posFinal = this.lastButtonClicked.getBoundingClientRect()
const dropdown = this.$refs.dropdown
console.log('defense', dropdown)
console.log('posfinal', posFinal)
return {
top: (posFinal.y + posFinal.height) + 'px',
left: posFinal.x + 'px'
}
},
createameliorer(){
} ,
createparam(){
},
createattaque(){
},
createbatiment(){
}
}
}
</script>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
},
methods:{
createdefense(evt){
this.showdefense = !this.showdefense
this.lastButtonCliked = evt.target
}
}
</script>