Skip to content

Instantly share code, notes, and snippets.

@nabettu
Created September 9, 2018 14:56
Show Gist options
  • Save nabettu/0a488d185d72417f83ae615bb1f1dbc6 to your computer and use it in GitHub Desktop.
Save nabettu/0a488d185d72417f83ae615bb1f1dbc6 to your computer and use it in GitHub Desktop.
横スクロール追従ヘッダーコンポーネント
<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