質問編集履歴

3

追記 このパターンのドロップダウン は動きます。

2019/10/10 02:53

投稿

ichigob
ichigob

スコア27

test CHANGED
File without changes
test CHANGED
@@ -423,3 +423,35 @@
423
423
  </div>
424
424
 
425
425
  ```
426
+
427
+
428
+
429
+ ## 追記 このパターンのドロップダウン は動きます。
430
+
431
+ ```ここに言語を入力
432
+
433
+ <div class="hoge-custom-select-wrap">
434
+
435
+ <div class="hoge-custom-select-main">
436
+
437
+
438
+
439
+ <select type="text" name="location" id="s">
440
+
441
+ <option value="">テスト</option>
442
+
443
+ <option value="">テスト</option>
444
+
445
+ <option value="">テスト</option>
446
+
447
+ <option value="">テスト</option>
448
+
449
+ </select>
450
+
451
+
452
+
453
+ </div>
454
+
455
+ </div>
456
+
457
+ ```

2

追記 css と js を読み込むdivも入れたコードです。

2019/10/10 02:53

投稿

ichigob
ichigob

スコア27

test CHANGED
File without changes
test CHANGED
@@ -381,3 +381,45 @@
381
381
  },[[11,"manifest","common"]]]);
382
382
 
383
383
  ```
384
+
385
+
386
+
387
+ ## 追記 jsとcssは変更しない
388
+
389
+
390
+
391
+ 他のドロップダウンでもこちらのjsとcssを使っているため、上記のjsとcssは変更しない方法で解決したいと考えています。
392
+
393
+
394
+
395
+ 今回のはじめのプログラムのみ自動でリロードしてしまう状況です。
396
+
397
+
398
+
399
+
400
+
401
+ ## 追記 css と js を読み込むdivも入れたコードです。
402
+
403
+
404
+
405
+ ```ここに言語を入力
406
+
407
+ <div class="hoge-custom-select-wrap">
408
+
409
+ <div class="hoge-custom-select-main">
410
+
411
+
412
+
413
+ <select class = "yearlydropdown minimal" name="archive-dropdown" onclick ="document.location.href=this.options[this.selectedIndex].value;">
414
+
415
+ <?php wp_get_archives( array( 'type' => 'yearly', 'format' => 'option', 'post_type' => 'news', 'posts_per_page' => 5) ); ?>
416
+
417
+ </select>
418
+
419
+
420
+
421
+ </div>
422
+
423
+ </div>
424
+
425
+ ```

1

追加したCSS JSS を記載しました。 よろしくお願いいたします。

2019/10/10 02:51

投稿

ichigob
ichigob

スコア27

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,345 @@
39
39
 
40
40
 
41
41
  追加したcssやjsをそのままで、上記のプログラムを修正して、自動にリロードしないようにできないでしょうか。
42
+
43
+
44
+
45
+ ## 追記 CSS
46
+
47
+
48
+
49
+ ```ここに言語を入力
50
+
51
+ .hoge-custom-select-wrap {
52
+
53
+ max-width: 152px;
54
+
55
+ width: 100%;
56
+
57
+ }
58
+
59
+
60
+
61
+ .hoge-custom-select-wrap * {
62
+
63
+ -webkit-box-sizing: border-box;
64
+
65
+ box-sizing: border-box;
66
+
67
+ margin: 0;
68
+
69
+ padding: 0;
70
+
71
+ }
72
+
73
+
74
+
75
+ .hoge-custom-select {
76
+
77
+ display: none;
78
+
79
+ }
80
+
81
+
82
+
83
+ .hoge-custom-select-main {
84
+
85
+ display: -webkit-box;
86
+
87
+ display: -webkit-flex;
88
+
89
+ display: -ms-flexbox;
90
+
91
+ display: flex;
92
+
93
+ position: relative;
94
+
95
+ cursor: pointer;
96
+
97
+ }
98
+
99
+
100
+
101
+ @media screen and (min-width: 768px) {
102
+
103
+ .hoge-custom-select {
104
+
105
+ position: relative;
106
+
107
+ display: -webkit-box;
108
+
109
+ display: -webkit-flex;
110
+
111
+ display: -ms-flexbox;
112
+
113
+ display: flex;
114
+
115
+ cursor: pointer;
116
+
117
+ }
118
+
119
+ .hoge-custom-select-main {
120
+
121
+ display: none;
122
+
123
+ }
124
+
125
+ }
126
+
127
+
128
+
129
+ .hoge-custom-select-main select {
130
+
131
+ text-align: left;
132
+
133
+ opacity: 1;
134
+
135
+ width: 100%;
136
+
137
+ max-height: 24px;
138
+
139
+ padding: 0 0 0 45px;
140
+
141
+ background-color: #fff;
142
+
143
+ color: #000;
144
+
145
+ border: 1px solid #000;
146
+
147
+ border-radius: 0;
148
+
149
+ font-size: 16px !important;
150
+
151
+ -moz-appearance: none;
152
+
153
+ appearance: none;
154
+
155
+ -webkit-appearance: none;
156
+
157
+ }
158
+
159
+
160
+
161
+ .hoge-custom-select__icon {
162
+
163
+ position: absolute;
164
+
165
+ right: 0;
166
+
167
+ top: 0;
168
+
169
+ width: 22px;
170
+
171
+ height: 100%;
172
+
173
+ background-color: #eee;
174
+
175
+ border: 1px solid #000;
176
+
177
+ }
178
+
179
+
180
+
181
+ .hoge-custom-select-main > .hoge-custom-select__icon {
182
+
183
+ pointer-events: none;
184
+
185
+ }
186
+
187
+
188
+
189
+ .hoge-custom-select__icon::after {
190
+
191
+ position: absolute;
192
+
193
+ right: 1px;
194
+
195
+ top: 50%;
196
+
197
+ -webkit-transform: translate(-2px, -50%);
198
+
199
+ transform: translate(-2px, -50%);
200
+
201
+ content: '';
202
+
203
+ width: 0;
204
+
205
+ height: 0;
206
+
207
+ padding: 0;
208
+
209
+ border-left: 6px solid transparent;
210
+
211
+ border-right: 6px solid transparent;
212
+
213
+ border-top: 8px solid #2e2e2e;
214
+
215
+ }
216
+
217
+
218
+
219
+ .hoge-custom-select__box {
220
+
221
+ position: relative;
222
+
223
+ width: 100%;
224
+
225
+ max-width: 130px;
226
+
227
+ text-align: center;
228
+
229
+ background-color: #fff;
230
+
231
+ }
232
+
233
+
234
+
235
+ .hoge-custom-select__item {
236
+
237
+ border: 1px solid #000;
238
+
239
+ border-right: 0;
240
+
241
+ height: 24px;
242
+
243
+ }
244
+
245
+
246
+
247
+ .hoge-custom-select__menu {
248
+
249
+ position: absolute;
250
+
251
+ top: 24px;
252
+
253
+ left: 0;
254
+
255
+ z-index: 10;
256
+
257
+ display: none;
258
+
259
+ width: 100%;
260
+
261
+ max-height: 145px;
262
+
263
+ overflow-y: scroll;
264
+
265
+ -ms-overflow-style: none;
266
+
267
+ scrollbar-width: none;
268
+
269
+ background-color: #fff;
270
+
271
+ border: 1px solid #ccc;
272
+
273
+ border-top: 0;
274
+
275
+ }
276
+
277
+
278
+
279
+ .hoge-custom-select__menu::-webkit-scrollbar {
280
+
281
+ display: none;
282
+
283
+ }
284
+
285
+
286
+
287
+ .hoge-custom-select__menu.active {
288
+
289
+ display: block;
290
+
291
+ }
292
+
293
+
294
+
295
+ .hoge-custom-select__menu-item {
296
+
297
+ padding: 4px 0;
298
+
299
+ }
300
+
301
+
302
+
303
+ .hoge-custom-select__menu-item.active {
304
+
305
+ background-color: #000;
306
+
307
+ color: #fff;
308
+
309
+ cursor: auto;
310
+
311
+ }
312
+
313
+
314
+
315
+ .hoge-custom-select__menu-item:not(:first-child):hover {
316
+
317
+ background-color: #eee;
318
+
319
+ }
320
+
321
+
322
+
323
+ /*# sourceMappingURL=scss-sourcemaps/global.css.map */
324
+
325
+
326
+
327
+ ```
328
+
329
+ ## 追記 js
330
+
331
+ ```ここに言語を入力
332
+
333
+ (window["webpackJsonp"] = window["webpackJsonp"] || []).push([["global"],{
334
+
335
+
336
+
337
+ /***/ "./src/js/global.js":
338
+
339
+ /*!**************************!*\
340
+
341
+ !*** ./src/js/global.js ***!
342
+
343
+ **************************/
344
+
345
+ /*! no static exports found */
346
+
347
+ /***/ (function(module, exports, __webpack_require__) {
348
+
349
+
350
+
351
+ eval("/* WEBPACK VAR INJECTION */(function($) {function hogeCustomSelect(elem) {\n $(function () {\n var copySelect = function copySelect($select, $dest) {\n $select = $($select), $dest = $($dest);\n $dest.empty();\n $select.children('option').each(function () {\n $dest.append('<div class=\"hoge-custom-select__menu-item\" value=\"' + $(this).val() + '\">' + $(this).html() + '</div>');\n });\n };\n var bindActive = function bindActive($select, $dest, direction) {\n $select = $($select), $dest = $($dest);\n if (direction === '>') {\n var val = $select.val();\n $dest.children().removeClass('active');\n $dest.find('[value=\"' + val + '\"]').addClass('active');\n } else if (direction === '<') {\n var _val = $dest.children('.active').attr('value');\n $select.val(_val);\n }\n };\n var sortItems = function sortItems($dest) {\n $dest = $($dest);\n var $items = $dest.children();\n $dest.html($items.sort(function (a, b) {\n if ($(a).hasClass('active')) return -1;\n return parseInt($(a).attr('value')) - parseInt($(b).attr('value'));\n }));\n };\n var $wrap = $(elem);\n $wrap.each(function () {\n var $select = $(this).children('select');\n var $frame = $('<div class=\"hoge-custom-select\">\n <div class=\"hoge-custom-select__box\">\n <div class=\"hoge-custom-select__item js--toggle-menu-button\"></div>\n <div class=\"hoge-custom-select__menu\"></div>\n </div>\n <span class=\"hoge-custom-select__icon js--toggle-menu-button\"></span>\n </div>');\n var $menu = $frame.find('.hoge-custom-select__menu');\n $(this).after($frame);\n copySelect($(this).children('select'), $menu);\n $select.on('change', function () {\n bindActive($select, $menu, '>');\n sortItems($menu);\n $frame.find('.hoge-custom-select__item').empty().html($menu.find('.active').html());\n });\n var self = this;\n $menu.on('click', '>*', function () {\n var current_val = $menu.children('.active').attr('value');\n var val = $(this).attr('value');\n if (current_val !== val) {\n $menu.children().removeClass('active');\n $(this).addClass('active');\n sortItems($menu);\n bindActive($select, $menu, '<');\n $frame.find('.hoge-custom-select__item').empty().html($menu.find('.active').html());\n $select.trigger('change');\n }\n $menu.toggle(false);\n sortItems($menu);\n });\n $select.trigger('change');\n $frame.find('.js--toggle-menu-button').click(function () {\n $menu.toggle();\n });\n });\n });\n}\n\nhogeCustomSelect('.hoge-custom-select-main');\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! jquery */ \"./node_modules/jquery/dist/jquery.js\")))\n\n//# sourceURL=webpack:///./src/js/global.js?");
352
+
353
+
354
+
355
+ /***/ }),
356
+
357
+
358
+
359
+ /***/ 11:
360
+
361
+ /*!********************************!*\
362
+
363
+ !*** multi ./src/js/global.js ***!
364
+
365
+ ********************************/
366
+
367
+ /*! no static exports found */
368
+
369
+ /***/ (function(module, exports, __webpack_require__) {
370
+
371
+
372
+
373
+ eval("module.exports = __webpack_require__(/*! ./src/js/global.js */\"./src/js/global.js\");\n\n\n//# sourceURL=webpack:///multi_./src/js/global.js?");
374
+
375
+
376
+
377
+ /***/ })
378
+
379
+
380
+
381
+ },[[11,"manifest","common"]]]);
382
+
383
+ ```