質問編集履歴

1

情報の追記

2021/01/18 04:46

投稿

snsan
snsan

スコア5

test CHANGED
File without changes
test CHANGED
@@ -78,7 +78,115 @@
78
78
 
79
79
  ```
80
80
 
81
+ app/js/scripts.js
81
82
 
83
+ ```javascript
84
+
85
+
86
+
87
+
88
+
89
+ const slider = function(){
90
+
91
+ // Next(Prev)ボタンの取得
92
+
93
+ const next = document.querySelector(".next");
94
+
95
+ const prev = document.querySelector(".prev");
96
+
97
+
98
+
99
+ // liタグのwidthを取得
100
+
101
+ const sliderwidth = document.querySelector(".sliderlist__item");
102
+
103
+ let width = sliderwidth.clientWidth;
104
+
105
+
106
+
107
+ // slider(ul要素、li要素一覧)の取得
108
+
109
+ const sliderlist = document.querySelector(".sliderlist");
110
+
111
+ const sliderlist_item = document.querySelectorAll(".sliderlist__item")
112
+
113
+
114
+
115
+ // カウンターの設定
116
+
117
+ let counter = 0;
118
+
119
+
120
+
121
+ // イベントリスナー (next)
122
+
123
+ next.addEventListener("click", function(){
124
+
125
+ if(counter == sliderlist_item.length - 1) return; //ボタン連打対策
126
+
127
+ prev.style.display = "block";
128
+
129
+ sliderlist.style.transition = ".3s";
130
+
131
+ counter ++;
132
+
133
+ sliderlist.style.transform = "translateX("+ (- width * counter) + "px)";
134
+
135
+
136
+
137
+ sliderlist.addEventListener("transitionend", function(){
138
+
139
+ if(counter == sliderlist_item.length - 1){
140
+
141
+ sliderlist.style.transition = "none";
142
+
143
+ next.style.display = "none";
144
+
145
+ }
146
+
147
+ })
148
+
149
+ });
150
+
151
+
152
+
153
+ // イベントリスナー (prev)
154
+
155
+ prev.addEventListener("click", function(){
156
+
157
+ if(counter == sliderlist_item.length - sliderlist_item.length) return; //ボタン連打対策
158
+
159
+ next.style.display = "block";
160
+
161
+ sliderlist.style.transition = ".3s";
162
+
163
+ counter --;
164
+
165
+ sliderlist.style.transform = "translateX("+ (- width * counter) + "px)";
166
+
167
+
168
+
169
+ sliderlist.addEventListener("transitionend", function(){
170
+
171
+ if(counter == sliderlist_item.length - sliderlist_item.length){
172
+
173
+ sliderlist.style.transition = "none";
174
+
175
+ prev.style.display = "none";
176
+
177
+ }
178
+
179
+ })
180
+
181
+ });
182
+
183
+ };
184
+
185
+
186
+
187
+ slider();
188
+
189
+ ```
82
190
 
83
191
  rails6ではpack_tagを使用し、application.jsでのパスの記述方法も間違えてはいないはずなのでそのほかで何かが間違えていると思います。
84
192