@Serjio30

Почему не работает функция clearInterval?

Вроде всё правильно написано. Пробовал уже все таймеры удалять, думал может из-за того что их много не работает. Все равно ничего.

function animationFirst () {
		 function animationRight () {
		$("h1").offset({ left: 200	});
		};
		 function animationDown () { 
		$("h1").offset({ top: 200	}); 
		};
		 function animationLeft () { 
		$("h1").offset({ left: 0 }); 
		};
		 function animationUp () { 
		$("h1").offset({ top: 0	}); 
		};
		setTimeout(animationRight, 500);
		setTimeout(animationDown, 1000);
		setTimeout(animationLeft, 1500);
		setTimeout(animationUp, 2000);
};

	function animationSecond () {
		 function animationDown () { 
		$("h1").offset({ top: 200	}); 
		};
		function animationRight () {
		$("h1").offset({ left: 200	});
		};
		function animationUp () { 
		$("h1").offset({ top: 0	}); 
		};
		 function animationLeft () { 
		$("h1").offset({ left: 0 }); 
		};
		setTimeout(animationDown, 500);
		setTimeout(animationRight, 1000);
		setTimeout(animationUp, 1500);
		setTimeout(animationLeft, 2000);
};
		function animation () {
			animationFirst();
			setTimeout(animationSecond, 2000);
			}


                animation();
		
		setInterval(animation, 4000);
		var stopAnimation = setInterval(animation, 4000);
		clearInterval(stopAnimation);
  • Вопрос задан
  • 79 просмотров
Решения вопроса 1
@Arrow_MGD
У тебя дважды интервал запускается:
setInterval(animation, 4000);
var stopAnimation = setInterval(animation, 4000);
clearInterval(stopAnimation);

Ты один закрываешь, а второй (который первым вызвал) продолжает работать
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы