Cимвольная анимация
Всем Привет !
Такая задачка, есть "символьная строка", написал код, что бы при заходе на сайт она опускалась сверху в низ по вертикали на 300px. Такой вопрос: Как после этой не сложной операции, сделать так, чтобы эта "символьная строка" исчезла(удалилась) и скажем через 4 секунды моя функция выполнилась заново ? Код прилагаю: (function() { var delay = 100, i = 0, startTimer = function (){ //console.log('функция startTimer сработала') var elem = document.getElementById('zaglav'), bottom = elem.offsetTop; if (i<10) { setTimeout(startTimer, delay); elem.style.top = bottom + 10 + 'px'; } i++; }; var timer = setTimeout(startTimer, delay); //alert('Алерт !!!'); })(); |
Все решили !!! Кому интересно
(function() { var delay = 100, i = 0, startTimer = function (){ //console.log('функция startTimer сработала') var elem = document.getElementById('zaglav'), bottom = elem.offsetTop; if (i<10) { //console.log('функция startTimer '+(i+1)+' сработала') setTimeout(startTimer, delay); elem.style.top = bottom + 10 + 'px'; }else{ function pause(ms) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < ms); }; pause(2000) elem.parentNode.removeChild(elem); } i++; }; var timer = setTimeout(startTimer, delay); })(); |
Цитата:
|
Есть другие варианты ??
|
Rom@n,
<!DOCTYPE HTML> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> <!-- --> </style> </head> <body> <div id="im" style="z-index:222;position:fixed;top:-65px;left:0; width:250px;height:65px; color:#fff; border:1px solid #4767AB; text-shadow: 1px 1px 1px #000; background:#4c83c3;box-shadow:0 0 2px rgba(0,0,0,0.9);"> НОВОЕ СООБЩЕНИЕ<br> От<br> Пан или пропал </div> <script> (function() { var element = document.getElementById("im"); function animate(el,from, to, style, time, complete) { var last = +new Date(), tick = function() { from += (new Date() - last)*to / time ; last = +new Date(); if (from < to) { (window.requestAnimationFrame && requestAnimationFrame(tick))|| setTimeout(tick, 16); } else {from = to}; el.style[style] = from + "px" ; from == to && complete() }; tick() } function first() { element.style.display = ''; animate(element, 0, 300,"top", 1500, pause); } function pause() { element.style.display = 'none'; setTimeout(first, 4000); } first() })(); </script> </body> </html> |
Часовой пояс GMT +3, время: 21:55. |