質問編集履歴

2

情報追加

2017/08/29 06:42

投稿

massiveGorilla
massiveGorilla

スコア21

test CHANGED
File without changes
test CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  画像を切り抜きpostするプラグインです。
4
4
 
5
- http://ultimateman.hahaue.com/
5
+ [http://ultimateman.hahaue.com/](http://ultimateman.hahaue.com/)
6
6
 
7
7
  これをfirefoxで起動しますと、誤作動があります。
8
8
 
9
+ バージョンは55.0.3(最新)で確認できております。
10
+
9
11
  画像アップロード箇所が2箇所あるのですが、1番目の操作は問題なく遂行されます。
10
12
 
11
13
  しかし2番目に操作した方では、本来画像ドラッグで操作できるべきところがオンマウスで追従してきてドラッグができなくなります。
@@ -15,3 +17,383 @@
15
17
  これはfirefoxのみでおこる問題です。
16
18
 
17
19
  拙いですが、よろしくお願いします。
20
+
21
+
22
+
23
+ 下記、jsソース
24
+
25
+ ```javascript
26
+
27
+ var cropbox1 = function(options){
28
+
29
+ var el = document.querySelector(options.imageBox),
30
+
31
+ obj =
32
+
33
+ {
34
+
35
+ state : {},
36
+
37
+ ratio : 1,
38
+
39
+ touchmove_bar : 0,
40
+
41
+ touchstart_bar : 0,
42
+
43
+ options : options,
44
+
45
+ imageBox : el,
46
+
47
+ thumbBox : el.querySelector(options.thumbBox),
48
+
49
+ spinner : el.querySelector(options.spinner),
50
+
51
+ image : new Image(),
52
+
53
+ getDataURL: function ()
54
+
55
+ {
56
+
57
+ var width = this.thumbBox.clientWidth,
58
+
59
+ height = this.thumbBox.clientHeight,
60
+
61
+ canvas = document.createElement("canvas"),
62
+
63
+ dim = el.style.backgroundPosition.split(' '),
64
+
65
+ size = el.style.backgroundSize.split(' '),
66
+
67
+ dx = parseInt(dim[0]) - el.clientWidth/2 + width/2,
68
+
69
+ dy = parseInt(dim[1]) - el.clientHeight/2 + height/2,
70
+
71
+ dw = parseInt(size[0]),
72
+
73
+ dh = parseInt(size[1]),
74
+
75
+ sh = parseInt(this.image.height),
76
+
77
+ sw = parseInt(this.image.width);
78
+
79
+
80
+
81
+ canvas.width = width;
82
+
83
+ canvas.height = height;
84
+
85
+ var context = canvas.getContext("2d");
86
+
87
+ context.drawImage(this.image, 0, 0, sw, sh, dx, dy, dw, dh);
88
+
89
+ var imageData = canvas.toDataURL('image/png');
90
+
91
+ return imageData;
92
+
93
+ },
94
+
95
+ getBlob: function()
96
+
97
+ {
98
+
99
+ var imageData = this.getDataURL();
100
+
101
+ var b64 = imageData.replace('data:image/png;base64,','');
102
+
103
+ var binary = atob(b64);
104
+
105
+ var array = [];
106
+
107
+ for (var i = 0; i < binary.length; i++) {
108
+
109
+ array.push(binary.charCodeAt(i));
110
+
111
+ }
112
+
113
+ return new Blob([new Uint8Array(array)], {type: 'image/png'});
114
+
115
+ },
116
+
117
+ zoomIn: function ()
118
+
119
+ {
120
+
121
+ this.ratio*=1.1;
122
+
123
+ setBackground();
124
+
125
+ },
126
+
127
+ zoomOut: function ()
128
+
129
+ {
130
+
131
+ this.ratio*=0.9;
132
+
133
+ setBackground();
134
+
135
+ },
136
+
137
+ imgTouch: function ()
138
+
139
+ {
140
+
141
+ setBackground();
142
+
143
+ }
144
+
145
+ },
146
+
147
+ attachEvent = function(node, event, cb)
148
+
149
+ {
150
+
151
+ if (node.attachEvent)
152
+
153
+ node.attachEvent('on'+event, cb);
154
+
155
+ else if (node.addEventListener)
156
+
157
+ node.addEventListener(event, cb);
158
+
159
+ },
160
+
161
+ detachEvent = function(node, event, cb)
162
+
163
+ {
164
+
165
+ if(node.detachEvent) {
166
+
167
+ node.detachEvent('on'+event, cb);
168
+
169
+ }
170
+
171
+ else if(node.removeEventListener) {
172
+
173
+ node.removeEventListener(event, render);
174
+
175
+ }
176
+
177
+ },
178
+
179
+ stopEvent = function (e) {
180
+
181
+ if(window.event) e.cancelBubble = true;
182
+
183
+ else e.stopImmediatePropagation();
184
+
185
+ },
186
+
187
+ setBackground = function()
188
+
189
+ {
190
+
191
+ var w = parseInt(obj.image.width)*obj.ratio;
192
+
193
+ var h = parseInt(obj.image.height)*obj.ratio;
194
+
195
+
196
+
197
+ var pw = (el.clientWidth - w) / 2;
198
+
199
+ var ph = (el.clientHeight - h) / 2;
200
+
201
+
202
+
203
+ el.setAttribute('style',
204
+
205
+ 'background-image: url(' + obj.image.src + '); ' +
206
+
207
+ 'background-size: ' + w +'px ' + h + 'px; ' +
208
+
209
+ 'background-position: ' + pw + 'px ' + ph + 'px; ' +
210
+
211
+ 'background-repeat: no-repeat');
212
+
213
+ },
214
+
215
+ imgMouseDown = function(e)
216
+
217
+ {
218
+
219
+ stopEvent(e);
220
+
221
+
222
+
223
+ obj.state.dragable = true;
224
+
225
+ obj.state.mouseX = e.clientX;
226
+
227
+ obj.state.mouseY = e.clientY;
228
+
229
+ },
230
+
231
+ imgMouseMove = function(e)
232
+
233
+ {
234
+
235
+ stopEvent(e);
236
+
237
+
238
+
239
+ if (obj.state.dragable)
240
+
241
+ {
242
+
243
+ var x = e.clientX - obj.state.mouseX;
244
+
245
+ var y = e.clientY - obj.state.mouseY;
246
+
247
+
248
+
249
+ var bg = el.style.backgroundPosition.split(' ');
250
+
251
+
252
+
253
+ var bgX = x + parseInt(bg[0]);
254
+
255
+ var bgY = y + parseInt(bg[1]);
256
+
257
+
258
+
259
+ el.style.backgroundPosition = bgX +'px ' + bgY + 'px';
260
+
261
+
262
+
263
+ obj.state.mouseX = e.clientX;
264
+
265
+ obj.state.mouseY = e.clientY;
266
+
267
+ }
268
+
269
+ },
270
+
271
+ imgMouseUp = function(e)
272
+
273
+ {
274
+
275
+ stopEvent(e);
276
+
277
+ obj.state.dragable = false;
278
+
279
+ },
280
+
281
+ zoomImage = function(e)
282
+
283
+ {
284
+
285
+ var evt=window.event || e;
286
+
287
+ var delta=evt.detail? evt.detail*(-120) : evt.wheelDelta;
288
+
289
+ delta > -120 ? obj.ratio*=1.1 : obj.ratio*=0.9;
290
+
291
+ setBackground();
292
+
293
+ },
294
+
295
+ imgTouchstart = function(e){
296
+
297
+ if(e.touches.length > 1){
298
+
299
+ }
300
+
301
+ else{
302
+
303
+ stopEvent(e);
304
+
305
+ obj.state.dragable = true;
306
+
307
+ obj.state.mouseX = e.touches[0].pageX;
308
+
309
+ obj.state.mouseY = e.touches[0].pageY;
310
+
311
+ }
312
+
313
+ },
314
+
315
+ imgTouchmove = function(e){
316
+
317
+ if(e.touches.length > 1){
318
+
319
+ }
320
+
321
+ else{
322
+
323
+ stopEvent(e);
324
+
325
+ if (obj.state.dragable){
326
+
327
+ var x = e.touches[0].pageX - obj.state.mouseX;
328
+
329
+ var y = e.touches[0].pageY - obj.state.mouseY;
330
+
331
+ var bg = el.style.backgroundPosition.split(' ');
332
+
333
+ var bgX = x + parseInt(bg[0]);
334
+
335
+ var bgY = y + parseInt(bg[1]);
336
+
337
+ el.style.backgroundPosition = bgX +'px ' + bgY + 'px';
338
+
339
+ obj.state.mouseX = e.touches[0].pageX;
340
+
341
+ obj.state.mouseY = e.touches[0].pageY;
342
+
343
+ }
344
+
345
+ }
346
+
347
+ },
348
+
349
+ imgTouchend = function(e){
350
+
351
+ if(e.touches.length == 1){
352
+
353
+ stopEvent(e);
354
+
355
+ obj.state.dragable = false;
356
+
357
+ }
358
+
359
+ }
360
+
361
+ obj.spinner.style.display = 'block';
362
+
363
+ obj.image.onload = function() {
364
+
365
+ obj.spinner.style.display = 'none';
366
+
367
+ setBackground();
368
+
369
+
370
+
371
+ attachEvent(el, 'mousedown', imgMouseDown);
372
+
373
+ attachEvent(el, 'mousemove', imgMouseMove);
374
+
375
+ attachEvent(document.body, 'mouseup', imgMouseUp);
376
+
377
+ var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
378
+
379
+ attachEvent(el, mousewheel, zoomImage);
380
+
381
+ attachEvent(el, 'touchstart', imgTouchstart,false);
382
+
383
+ attachEvent(el, 'touchmove', imgTouchmove);
384
+
385
+ attachEvent(el, 'touchend', imgTouchend);
386
+
387
+ };
388
+
389
+ obj.image.src = options.imgSrc;
390
+
391
+ attachEvent(el, 'DOMNodeRemoved', function(){detachEvent(document.body, 'DOMNodeRemoved', imgMouseUp)});
392
+
393
+
394
+
395
+ return obj;
396
+
397
+ };
398
+
399
+ ```

1

誤字

2017/08/29 06:42

投稿

massiveGorilla
massiveGorilla

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ↓こちらはデモページです。
2
2
 
3
- jqueryで画像を切り抜きpostするプラグインです。
3
+ 画像を切り抜きpostするプラグインです。
4
4
 
5
5
  http://ultimateman.hahaue.com/
6
6