Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Как вернуть анимированному <title> прежнее значение? (https://javascript.ru/forum/misc/48969-kak-vernut-animirovannomu-title-prezhnee-znachenie.html)

tuchkovo-auto 23.07.2014 20:11

Как вернуть анимированному <title> прежнее значение?
 
Всем привет!
Имею код:
<html><head><title>Бегущая строка.</title>
<script>(function titleMarquee(){document.title=document.title.substring(1)+document.title.substring(0,1);
orgn_ttl=setTimeout(titleMarquee,600);})();</script></head>
<body>
<button title="Stop The Title" onclick="clearTimeout(orgn_ttl);">
Stop Title</button>
</body></html>

Необходимо остановить анимированный <title> и вернуть первоначальную позицию. Т.е. кнопка <button> его останавливает, но не возращает первоначальное положение- текст просто замирает посередине. Хотелось-бы что-бы анимация не только останавливалась но и <title> принимал исходное положение.

Rise 23.07.2014 20:56

tuchkovo-auto,
<script>var defaultTitle=document.title;(function titleMarquee(){document.title=document.title.substring(1)+document.title.substring(0,1);orgn_ttl=setTimeout(titleMarquee,600);})();</script>

<button title="Stop The Title" onclick="clearTimeout(orgn_ttl);document.title=defaultTitle;">Stop Title</button>

рони 23.07.2014 20:58

tuchkovo-auto,
:cray:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
  <title>Бегущая строка.</title>
  <script>
var title = document.title,
     orgn_ttl;
 function titleMarquee(a) {
     a ? (clearTimeout(orgn_ttl), document.title = title) : (document.title = document.title.substring(1) + document.title.substring(0, 1), orgn_ttl = setTimeout(titleMarquee, 600))
 }
 titleMarquee();
  </script>
</head>

<body>
  <button title="Stop The Title" onclick="titleMarquee(true)">Stop Title</button>
</body>
</html>

MallSerg 23.07.2014 20:58

<!Doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>Бегущая строка::</title>
</head>
<body>
	<form name="form_1">
		<input type="button"  name="button_1" value="Stop Title">
		<input type="button"  name="button_2" value="Star Title">
	</form>
</body>	
	<script>
		ot = document.title;
		document.form_1.button_1.onclick = function()
		{
			clearTimeout(orgn_ttl);
			document.title = ot;
		}
		title = document.form_1.button_2.onclick = function()
		{
				var s = document.title;
				document.title = s.substr(1) + s.substr(0,1);
				orgn_ttl = setTimeout ( title, 132 ) ;
		};
		title();
	</script>
</html>

рони 23.07.2014 21:00

:)

tuchkovo-auto 23.07.2014 21:20

Ребята всем Спасибо! У всех скрипты работают, но выберу пожалуй скрипт от MallSerg, этот скрипт и на странице, и в выносном скрипте с jQuery работает!


Часовой пояс GMT +3, время: 12:13.