回答編集履歴
3
調整
test
CHANGED
@@ -75,3 +75,46 @@
|
|
75
75
|
</div>
|
76
76
|
</div>
|
77
77
|
```
|
78
|
+
|
79
|
+
# 調整版
|
80
|
+
移動中や移動後にboxをクリックしても反応しないようにする
|
81
|
+
```javascript
|
82
|
+
<script>
|
83
|
+
function boxslideAimation(element,distances,duration){
|
84
|
+
if(element.matches('[data-active]')) return false;
|
85
|
+
element.dataset.active=1
|
86
|
+
const myKeyframe= new KeyframeEffect(
|
87
|
+
element,
|
88
|
+
[
|
89
|
+
{transform: `translate(0px,0px)`},
|
90
|
+
{transform: `translate(${distances[0]}px,${distances[1]}px)`},
|
91
|
+
],
|
92
|
+
{duration,fill: "forwards" }
|
93
|
+
);
|
94
|
+
const myAnime = new Animation(myKeyframe,document.timeline);
|
95
|
+
myAnime.play();
|
96
|
+
};
|
97
|
+
function styleReset(){
|
98
|
+
delete(box.dataset.active);
|
99
|
+
boxslideAimation(box,[0,0],0);
|
100
|
+
delete(box.dataset.active);
|
101
|
+
}
|
102
|
+
</script>
|
103
|
+
<style>
|
104
|
+
.place{
|
105
|
+
height:500px;
|
106
|
+
background-Color:gray;
|
107
|
+
}
|
108
|
+
#box{
|
109
|
+
background-Color:yellow;
|
110
|
+
width:100px;
|
111
|
+
height:100px;
|
112
|
+
}
|
113
|
+
</style>
|
114
|
+
<div class="place">
|
115
|
+
<button onclick="styleReset()">リセット</button>
|
116
|
+
<div id="box" onclick="boxslideAimation(this,[500,300],2000)">
|
117
|
+
<p>box</p>
|
118
|
+
</div>
|
119
|
+
</div>
|
120
|
+
```
|
2
chousei
test
CHANGED
@@ -12,13 +12,11 @@
|
|
12
12
|
.place{
|
13
13
|
height:500px;
|
14
14
|
background-Color:gray;
|
15
|
-
position:relative;
|
16
15
|
}
|
17
16
|
#box{
|
18
17
|
background-Color:yellow;
|
19
18
|
width:100px;
|
20
19
|
height:100px;
|
21
|
-
position:absolute;
|
22
20
|
}
|
23
21
|
#box.slide{
|
24
22
|
animation:slide 2s;
|
@@ -63,13 +61,11 @@
|
|
63
61
|
.place{
|
64
62
|
height:500px;
|
65
63
|
background-Color:gray;
|
66
|
-
position:relative;
|
67
64
|
}
|
68
65
|
#box{
|
69
66
|
background-Color:yellow;
|
70
67
|
width:100px;
|
71
68
|
height:100px;
|
72
|
-
position:absolute;
|
73
69
|
}
|
74
70
|
</style>
|
75
71
|
<div class="place">
|
1
追記
test
CHANGED
@@ -36,3 +36,46 @@
|
|
36
36
|
</div>
|
37
37
|
</div>
|
38
38
|
```
|
39
|
+
|
40
|
+
|
41
|
+
# 追記
|
42
|
+
jsバージョンです
|
43
|
+
CSS版とちょっと仕様がちがうので注意ください
|
44
|
+
```javascript
|
45
|
+
<script>
|
46
|
+
function boxslideAimation(element,distances,duration){
|
47
|
+
const myKeyframe= new KeyframeEffect(
|
48
|
+
element,
|
49
|
+
[
|
50
|
+
{transform: `translate(0px,0px)`},
|
51
|
+
{transform: `translate(${distances[0]}px,${distances[1]}px)`},
|
52
|
+
],
|
53
|
+
{duration,fill: "forwards" }
|
54
|
+
);
|
55
|
+
const myAnime = new Animation(myKeyframe,document.timeline);
|
56
|
+
myAnime.play();
|
57
|
+
};
|
58
|
+
function styleReset(){
|
59
|
+
boxslideAimation(box,[0,0],0);
|
60
|
+
}
|
61
|
+
</script>
|
62
|
+
<style>
|
63
|
+
.place{
|
64
|
+
height:500px;
|
65
|
+
background-Color:gray;
|
66
|
+
position:relative;
|
67
|
+
}
|
68
|
+
#box{
|
69
|
+
background-Color:yellow;
|
70
|
+
width:100px;
|
71
|
+
height:100px;
|
72
|
+
position:absolute;
|
73
|
+
}
|
74
|
+
</style>
|
75
|
+
<div class="place">
|
76
|
+
<button onclick="styleReset()">リセット</button>
|
77
|
+
<div id="box" onclick="boxslideAimation(this,[500,300],2000)">
|
78
|
+
<p>box</p>
|
79
|
+
</div>
|
80
|
+
</div>
|
81
|
+
```
|