回答編集履歴

4

追記

2019/11/15 05:35

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -72,6 +72,8 @@
72
72
 
73
73
  const spead = 1; //速さ(小さいと早い)
74
74
 
75
+ const supsp = 1; //速さ(大きいと早い・大きくしすぎるとカクカクになる)
76
+
75
77
 
76
78
 
77
79
  const tochu = window.innerWidth / 2 - width / 2;
@@ -98,7 +100,7 @@
98
100
 
99
101
  }
100
102
 
101
- i += 1;
103
+ i += supsp;
102
104
 
103
105
  }, spead);
104
106
 

3

追記

2019/11/15 05:35

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -62,11 +62,23 @@
62
62
 
63
63
  ```jQuery
64
64
 
65
+
66
+
67
+ const loopTime = 10000; //繰り返し時間
68
+
69
+ const width = 200; //要素の幅
70
+
71
+ const stopTime = 1000; //停車時間
72
+
73
+ const spead = 1; //速さ(小さいと早い)
74
+
75
+
76
+
65
- const tochu = window.innerWidth / 2 - 100;
77
+ const tochu = window.innerWidth / 2 - width / 2;
66
78
 
67
79
  setInterval(function(){
68
80
 
69
- i=-200;
81
+ i= - width;
70
82
 
71
83
  car = setInterval(function(){
72
84
 
@@ -74,25 +86,27 @@
74
86
 
75
87
  document.getElementById('track').style.left = i + 'px';
76
88
 
77
- } else if(i>window.innerWidth+2000) {
89
+ } else if(i>window.innerWidth+stopTime) {
78
90
 
79
91
  clearInterval(car);
80
92
 
81
- } else if (i>tochu+1000) {
93
+ } else if (i>tochu+stopTime) {
82
94
 
83
- document.getElementById('track').style.left = i - 1000 + 'px';
95
+ document.getElementById('track').style.left = i - stopTime + 'px';
84
96
 
85
- document.getElementById('ushi').style.left = i - 1000 + 'px';
97
+ document.getElementById('ushi').style.left = i - stopTime + 'px';
86
98
 
87
99
  }
88
100
 
89
- i += 4;
101
+ i += 1;
90
102
 
91
- }, 4);
103
+ }, spead);
92
104
 
93
105
  document.getElementById('ushi').style.left = tochu + 'px';
94
106
 
95
- }, 5000);
107
+ }, loopTime);
108
+
109
+
96
110
 
97
111
  ```
98
112
 

2

追記

2019/11/15 05:32

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -62,13 +62,37 @@
62
62
 
63
63
  ```jQuery
64
64
 
65
- var tochu = $('#ushi').position().left;
65
+ const tochu = window.innerWidth / 2 - 100;
66
66
 
67
- $('#track').animate({'left':tochu},1000,'swing');
67
+ setInterval(function(){
68
68
 
69
- $('#track').delay('1000').animate({'left':window.innerWidth},1000,'swing');
69
+ i=-200;
70
70
 
71
+ car = setInterval(function(){
72
+
73
+ if(tochu>i){
74
+
75
+ document.getElementById('track').style.left = i + 'px';
76
+
77
+ } else if(i>window.innerWidth+2000) {
78
+
79
+ clearInterval(car);
80
+
81
+ } else if (i>tochu+1000) {
82
+
83
+ document.getElementById('track').style.left = i - 1000 + 'px';
84
+
71
- $('#ushi').delay('2000').animate({'left':window.innerWidth},1000,'swing');
85
+ document.getElementById('ushi').style.left = i - 1000 + 'px';
86
+
87
+ }
88
+
89
+ i += 4;
90
+
91
+ }, 4);
92
+
93
+ document.getElementById('ushi').style.left = tochu + 'px';
94
+
95
+ }, 5000);
72
96
 
73
97
  ```
74
98
 

1

追記

2019/11/15 02:17

投稿

kyoya0819
kyoya0819

スコア10429

test CHANGED
@@ -1 +1,75 @@
1
1
  この程度でしたらJavaScriptかCSSのkeyframeでできます。(サンプルコードは明日までに提示します
2
+
3
+
4
+
5
+ めんどくさいのでjQueryで書いています
6
+
7
+ ```HTML
8
+
9
+ <img id=ushi src=>
10
+
11
+ <img id=house src=>
12
+
13
+ <img id=track src=>
14
+
15
+ ```
16
+
17
+ ```CSS
18
+
19
+ * {
20
+
21
+ margin: 0;
22
+
23
+ padding: 0
24
+
25
+ }
26
+
27
+ img {
28
+
29
+ position: absolute;
30
+
31
+ top: 0;
32
+
33
+ left: 0;
34
+
35
+ width: 200px
36
+
37
+ }
38
+
39
+ #track {
40
+
41
+ z-index: 100;
42
+
43
+ left: -200px
44
+
45
+ }
46
+
47
+ #ushi {
48
+
49
+ z-index: 50;
50
+
51
+ left: calc(50vw - 100px)
52
+
53
+ }
54
+
55
+ #house {
56
+
57
+ left: calc(50vw - 100px)
58
+
59
+ }
60
+
61
+ ```
62
+
63
+ ```jQuery
64
+
65
+ var tochu = $('#ushi').position().left;
66
+
67
+ $('#track').animate({'left':tochu},1000,'swing');
68
+
69
+ $('#track').delay('1000').animate({'left':window.innerWidth},1000,'swing');
70
+
71
+ $('#ushi').delay('2000').animate({'left':window.innerWidth},1000,'swing');
72
+
73
+ ```
74
+
75
+ [サンプル](https://codepen.io/asuchi0819/pen/gOOBNKV?editors=0010)