| 
									
										
										
										
											2020-04-18 18:29:31 -07:00
										 |  |  | <style> | 
					
						
							|  |  |  |   body, html { margin: 0; padding: 0; } | 
					
						
							|  |  |  |   @keyframes move { | 
					
						
							|  |  |  |     from { marign-left: 0; } | 
					
						
							|  |  |  |     to   { margin-left: 100px; } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | function addButton() { | 
					
						
							|  |  |  |   const button = document.createElement('button'); | 
					
						
							|  |  |  |   button.textContent = 'Click me'; | 
					
						
							|  |  |  |   button.style.animation = '3s linear move'; | 
					
						
							|  |  |  |   button.style.animationIterationCount = 'infinite'; | 
					
						
							|  |  |  |   button.addEventListener('click', () => window.clicked = true); | 
					
						
							|  |  |  |   document.body.appendChild(button); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-04-29 11:05:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 18:29:31 -07:00
										 |  |  | function stopButton(remove) { | 
					
						
							|  |  |  |   const button = document.querySelector('button'); | 
					
						
							|  |  |  |   button.style.marginLeft = button.getBoundingClientRect().left + 'px'; | 
					
						
							|  |  |  |   button.style.animation = ''; | 
					
						
							|  |  |  |   if (remove) | 
					
						
							|  |  |  |     button.remove(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-04-29 11:05:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | let x = 0; | 
					
						
							|  |  |  | function jump() { | 
					
						
							|  |  |  |   x += 300; | 
					
						
							| 
									
										
										
										
											2020-04-28 11:58:22 -07:00
										 |  |  |   const button = document.querySelector('button'); | 
					
						
							| 
									
										
										
										
											2020-04-29 11:05:23 -07:00
										 |  |  |   button.style.marginLeft = x + 'px'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function startJumping() { | 
					
						
							|  |  |  |   x = 0; | 
					
						
							| 
									
										
										
										
											2020-04-28 11:58:22 -07:00
										 |  |  |   const moveIt = () => { | 
					
						
							| 
									
										
										
										
											2020-04-29 11:05:23 -07:00
										 |  |  |     jump(); | 
					
						
							| 
									
										
										
										
											2020-04-28 11:58:22 -07:00
										 |  |  |     requestAnimationFrame(moveIt); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-04-29 11:05:23 -07:00
										 |  |  |   setInterval(jump, 0); | 
					
						
							| 
									
										
										
										
											2020-04-28 11:58:22 -07:00
										 |  |  |   moveIt(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-04-18 18:29:31 -07:00
										 |  |  | </script> |