/
18_file_api.html
63 lines (59 loc) · 1.78 KB
/
18_file_api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>クロスフェードスライド</title>
<link rel="stylesheet" href="./css/style.css">
<script src="./js/jquery-1.11.2.js"></script>
<script>
$(function(){
/*
$('.slide ul li').hide();
$('.slide ul li:first').addClass('active').show();
setInterval(function(){
var $active = $('.slide ul li.active');
var $next;
if($active.next('li').length == 1){
$next = $active.next('li');
}else{
$next = $('.slide ul li:first');
}
$active.fadeOut().removeClass('active');
$next.fadeIn().addClass('active');
},2000);
*/
//オブジェクトを生成
var reader = new FileReader();
//ドロップしたとき、ファイルを読み込む
$('.drop-frame').on('drop',function(e){
e.preventDefault();
for(var i = 0;i<e.originalEvent.dataTransfer.files.length ;i++){
reader.readAsDataURL(e.originalEvent.dataTransfer.files[i]);
}
});
//ドラッグしたときの処理
$('.drop-frame').on('dragover',function(e){
e.preventDefault();
});
//ファイルの読み込みが完了したときの処理
reader.addEventListener('load', function() {
//クロスフェードスライド用、サムネイル用のコードを生成、appendはセレクターの閉じタグ直前に任意のコードを追記出来る
$('.slide ul, .thumbnail ul').append('<li><img alt=""></li>');
$('.slide ul li:last img, .thumbnail ul li:last img').attr('src',reader.result);
});
});
</script>
</head>
<body>
<div class="slide">
<ul>
</ul>
</div>
<p class="drop-frame">ファイルをドラッグ&ドロップしてください</p>
<p class="start">start</p>
<div class="thumbnail">
<ul>
</ul>
</div>
</body>
</html>