質問編集履歴
1
コードを追加する
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,13 +8,143 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
hammer.jsをサーバーにアップロードして<script>タグでファイルを読み込んだ後に、utility.jsという別ファイルに
|
11
|
+
hammer.jsをサーバーにアップロードして<script>タグでファイルを読み込んだ後に、utility.jsという別ファイルに下のコードを書きました。
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```javascript
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
jQuery.noConflict();
|
24
|
+
|
25
|
+
(function($) {
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
var duringAnimation = false;//アニメーション中のロック用フラグ
|
30
|
+
|
31
|
+
var mc = new Hammer(document.getElementById("swiper")); **エラー部分**
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
mc.on("pan", function(e){
|
36
|
+
|
37
|
+
var viewItem = $(e.target).closest(".view-mode");
|
38
|
+
|
39
|
+
var positions = $(".position > li");
|
40
|
+
|
41
|
+
var index = $(viewItem).index();
|
42
|
+
|
43
|
+
var length = $(".view-mode").length;
|
44
|
+
|
45
|
+
var nextItem;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
var nextIndex;
|
50
|
+
|
51
|
+
var direction;
|
52
|
+
|
53
|
+
var range = 60;//判定する角度
|
54
|
+
|
55
|
+
var easing = 'ease';
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
if (e.distance < 70) return true;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//範囲外だったら処理しない。
|
64
|
+
|
65
|
+
if ( !(e.angle > -180 - range && e.angle < -180 + range) && !(e.angle < range && e.angle > -range)){
|
66
|
+
|
67
|
+
return true;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//方向
|
74
|
+
|
75
|
+
direction = (e.additionalEvent === "panleft") ? "left":"right";
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
var step = (direction === "left") ? 1:-1;
|
80
|
+
|
81
|
+
nextIndex = index + step;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
if (nextIndex > length-1)
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
nextIndex = 0;
|
90
|
+
|
91
|
+
}else if (nextIndex < 0){
|
92
|
+
|
93
|
+
nextIndex = length-1;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
nextItem = $(".view-mode")[nextIndex];
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
$(positions).removeClass("active");
|
106
|
+
|
107
|
+
$(positions[nextIndex]).addClass("active");
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//$("#position ul").animate({left: 0}, 100, "easeOutExpo");
|
112
|
+
|
113
|
+
$(window).scrollTop(0);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
if (duringAnimation === false) {
|
118
|
+
|
119
|
+
duringAnimation = true;
|
120
|
+
|
121
|
+
$(nextItem).css({"left":"100%", "display":"block"}).transition({left: "0"}, 300, easing);
|
122
|
+
|
123
|
+
$(viewItem).transition({left: (direction === "left") ? "-100%":"100%" }, 300, easing,function () {
|
124
|
+
|
125
|
+
$(viewItem).css({"position": "absolute", "display": "none"});
|
126
|
+
|
127
|
+
$(nextItem).css({"margin-top": "0", "position": "relative", "display": "block"});
|
128
|
+
|
129
|
+
duringAnimation = false;
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
})(jQuery); **エラー部分**
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```
|
144
|
+
|
15
145
|
すると『Uncaught ReferenceError: Hammer is not defined』という内容のエラーが出ます。
|
16
146
|
|
17
|
-
エラーが出ている場所は
|
147
|
+
エラーが出ている場所は、5行目の『var mc = new Hammer(document.getElementById('swiper'));』と、最後の行の『})(jQuery);』の部分です。
|
18
148
|
|
19
149
|
|
20
150
|
|