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

質問編集履歴

1

コードを追記、タイトル変更

2019/05/05 04:04

投稿

myc
myc

スコア18

title CHANGED
@@ -1,1 +1,1 @@
1
- iOSでクリックイベントが発しない
1
+ addEventListener登録したクリックイベントがiOSでしない
body CHANGED
@@ -7,6 +7,102 @@
7
7
  codepen
8
8
  [https://codepen.io/mycreatesite/pen/YbKvQL](https://codepen.io/mycreatesite/pen/YbKvQL)
9
9
 
10
+ ```html
11
+ <button id="openModal">Open modal</button>
12
+
13
+ <section id="modalArea" class="modalArea">
14
+ <div id="modalBg" class="modalBg"></div>
15
+ <div class="modalWrapper">
16
+ <div class="modalContents">
17
+ <h1>Here are modal without jQuery!</h1>
18
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
19
+ </div>
20
+ <div id="closeModal" class="closeModal">
21
+ ×
22
+ </div>
23
+ </div>
24
+ </section>
25
+ ```
26
+ ```css
27
+ * {
28
+ box-sizing: border-box;
29
+ }
30
+ body {
31
+ font-family:'Avenir','Helvetica, Neue','Helvetica','Arial';
32
+ }
33
+
34
+ .modalArea {
35
+ visibility: hidden;
36
+ opacity : 0;
37
+ position: fixed;
38
+ z-index: 10;
39
+ top: 0;
40
+ left: 0;
41
+ width: 100%;
42
+ height: 100%;
43
+ transition: .4s;
44
+ }
45
+
46
+ .modalBg {
47
+ width: 100%;
48
+ height: 100%;
49
+ background-color: rgba(30,30,30,0.9);
50
+ }
51
+
52
+ .modalWrapper {
53
+ position: absolute;
54
+ top: 50%;
55
+ left: 50%;
56
+ transform:translate(-50%,-50%);
57
+ width: 70%;
58
+ max-width: 500px;
59
+ padding: 10px 30px;
60
+ background-color: #fff;
61
+ }
62
+
63
+ .closeModal {
64
+ position: absolute;
65
+ top: 0.5rem;
66
+ right: 1rem;
67
+ cursor: pointer;
68
+ }
69
+
70
+ .is-show {
71
+ visibility: visible;
72
+ opacity : 1;
73
+ }
74
+
75
+ button {
76
+ padding: 10px;
77
+ background-color: #fff;
78
+ border: 1px solid #282828;
79
+ border-radius: 2px;
80
+ cursor: pointer;
81
+ }
82
+
83
+ #openModal {
84
+ position: absolute;
85
+ top: 50%;
86
+ left: 50%;
87
+ transform:translate(-50%,-50%);
88
+ }
89
+ ```
90
+ ```js
91
+ (function () {
92
+ const modalArea = document.getElementById('modalArea');
93
+ const openModal = document.getElementById('openModal');
94
+ const closeModal = document.getElementById('closeModal');
95
+ const modalBg = document.getElementById('modalBg');
96
+ const toggle = [openModal,closeModal,modalBg];
97
+
98
+ for(let i=0, len=toggle.length ; i<len ; i++){
99
+ toggle[i].addEventListener('click',function(){
100
+ modalArea.classList.toggle('is-show');
101
+ },false);
102
+ }
103
+ }());
104
+ ```
105
+
10
106
  ### 試したこと
11
107
 
12
108
  cssで発火要素にcursor:pointerを当てたり、イベントをclickではなくtouchstartにしてみても発火しない状態です。