Created
September 9, 2018 14:56
-
-
Save nabettu/0a488d185d72417f83ae615bb1f1dbc6 to your computer and use it in GitHub Desktop.
横スクロール追従ヘッダーコンポーネント
This file contains hidden or 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 lang="pug"> | |
header.header(:style="{left: headerScroll}") | |
.header__contents | |
</template> | |
<script> | |
export default { | |
name: "headerContent", | |
data: function() { | |
return { | |
headerScroll: 0, | |
}; | |
}, | |
mounted: function() { | |
window.addEventListener("scroll", this.handleScroll, false); | |
}, | |
beforeDestroy: function() { | |
window.removeEventListener("scroll", this.handleScroll, false); | |
}, | |
methods: { | |
handleScroll: function() { | |
this.headerScroll = -window.scrollX + "px"; | |
} | |
} | |
}; | |
</script> | |
<style lang="scss" scoped> | |
.header { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
min-width: 1000px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment