Last active
May 23, 2020 12:55
-
-
Save Bachana123/a0f8050266c83b03ae03e9c1dfb5701c to your computer and use it in GitHub Desktop.
scrolling with arrow
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
chooseWithArrows(e) { | |
const SCROLL_BOX = this.$refs.scrollWithArrow | |
let scrollDiv; | |
if (e.keyCode == '38') { | |
//check if i is smaller than 0 | |
this.i - 1 < 0 ? this.i = this.searchHendler.length-1 : this.i -=1; | |
//add animation using this variable | |
this.scrollTo = this.searchHendler[this.i][this.name] | |
//check offset of child component | |
scrollDiv = SCROLL_BOX.childNodes[this.i].offsetTop | |
//scroll in div to that component | |
SCROLL_BOX.scrollTop = scrollDiv | |
} | |
else if (e.keyCode == '40') { | |
this.i + 1 > this.searchHendler.length-1 ? this.i = 0 : this.i+=1; | |
this.scrollTo = this.searchHendler[this.i][this.name] | |
scrollDiv = SCROLL_BOX.childNodes[this.i].offsetTop | |
SCROLL_BOX.scrollTop = scrollDiv | |
} | |
//if you push enter | |
else if (e.keyCode == '13') { | |
this.onclick(this.searchHendler[this.i].id) | |
this.selected = this.searchHendler[this.i][this.name] | |
this.hide() | |
this.i = 0 | |
e.preventDefault(); | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment