質問するログイン新規登録

質問編集履歴

2

補足の追加

2020/05/22 10:11

投稿

smilax630
smilax630

スコア34

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  具体的にどんな施策が考えられるでしょうか
5
5
 
6
+ activeクラスがついてる間は、スクロールできないという状態を想定しています
7
+
6
8
  App.vue
7
9
  ```Vue
8
10
  <template>

1

コードの追加

2020/05/22 10:11

投稿

smilax630
smilax630

スコア34

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,136 @@
1
1
  ### 実現したいこと
2
2
  ハンバーガーメニューを押し、グローバルメニューが表示された時にスクロールできないようにしようと思い、動的クラスをつけ、position: fixed;を設定しました。スクロールの無効化はできましたが、topに戻ってしまいます。これをtopに戻さずそのままの状態で背景を固定したいです
3
3
 
4
- 具体的にどんな施策が考えられるでしょうか
4
+ 具体的にどんな施策が考えられるでしょうか
5
+
6
+ App.vue
7
+ ```Vue
8
+ <template>
9
+ <div id="app" :class="{ active: isActive }">
10
+ <Header @fixed="changeActive" ></Header>
11
+ <router-view/>
12
+ </div>
13
+ </template>
14
+
15
+ <script lang="ts">
16
+ import Vue from 'vue'
17
+ import Header from '@/components/Header.vue'
18
+ export type DataType = { isActive: boolean }
19
+ export default Vue.extend({
20
+ components: {
21
+ Header
22
+ },
23
+ data(): DataType{
24
+ return {
25
+ isActive: false
26
+ }
27
+ },
28
+ methods: {
29
+ changeActive() {
30
+ this.isActive = !this.isActive
31
+ },
32
+ }
33
+ })
34
+ </script>
35
+ <style>
36
+ body {
37
+ margin: 0;
38
+ }
39
+ .active {
40
+ position: fixed;
41
+ }
42
+ #app {
43
+ font-family: Avenir, Helvetica, Arial, sans-serif;
44
+ -webkit-font-smoothing: antialiased;
45
+ -moz-osx-font-smoothing: grayscale;
46
+ text-align: center;
47
+ color: #2c3e50;
48
+ }
49
+ </style>
50
+
51
+ ```
52
+
53
+
54
+ Header.vue
55
+ ```Vue
56
+ <template lang="pug">
57
+ .head
58
+ .header
59
+ NAV(:aa="clickHumb")
60
+ img.logo(src="../assets/hobo_logo.svg" alt="logo")
61
+ .humb(@click="openMenu")
62
+ .first-line
63
+ .last-line
64
+ </template>
65
+ <script lang="ts">
66
+ import Vue from 'vue'
67
+ import NAV from '@/components/Nav.vue'
68
+
69
+ export type DataType = { clickHumb: boolean }
70
+ export default Vue.extend({
71
+ data(): DataType {
72
+ return {
73
+ clickHumb: false
74
+ }
75
+ },
76
+ components: {
77
+ NAV
78
+ },
79
+
80
+ methods: {
81
+ openMenu() {
82
+ this.clickHumb = !this.clickHumb
83
+
84
+ if (this.clickHumb === true){
85
+ this.$emit('fixed')
86
+ }
87
+ }
88
+ }
89
+ })
90
+ </script>
91
+
92
+ <style scoped>
93
+ .head {
94
+ height: 60px;
95
+ }
96
+ .header{
97
+ position: relative;
98
+ width: 100%;
99
+ }
100
+ .header:hover > .logo{
101
+ opacity: 0.7;
102
+ }
103
+ .logo{
104
+ width: 150px;
105
+ margin-top: 5px;
106
+ margin-bottom: 5px;
107
+ transition: opacity 0.4s;
108
+ }
109
+ .humb{
110
+ width: 35px;
111
+ display: inline-block;
112
+ position: fixed;
113
+ top: 10px;
114
+ right: 10px;
115
+ padding-top: 20px;
116
+ padding-right: 20px;
117
+ padding-bottom: 10px;
118
+ }
119
+ .humb:hover > .first-line{
120
+ transform: translateY(3px);
121
+ }
122
+ .humb:hover > .last-line{
123
+ transform: translateY(7px);
124
+ }
125
+ .first-line {
126
+ border-bottom: 2px solid dimgray;
127
+ margin-bottom: 13px;
128
+ transition: all 0.5s;
129
+
130
+ }
131
+ .last-line {
132
+ border-top: 2px solid dimgray;
133
+ transition: all 0.5s;
134
+ }
135
+ </style>
136
+ ```