Вопрос по скрипту для плавного появления текста

G
На сайте с 22.11.2013
Offline
2
1240
<script type="text/javascript">
$(document).ready(function(){
$.fn.animate_Text = function() {
var string = this.text();
return this.each(function(){
var $this = $(this);
$this.html(string.replace(/./g, '<span class="new">$&</span>'));
$this.find('span.new').each(function(i, el){
setTimeout(function(){ $(el).addClass('div_opacity'); }, 97 * i);
});
});
};
$('#example').show();
$('#example').animate_Text();
});

</script>

Есть вот такой скрипт. Предназначен для плавного появления текста. Пример можно посмотреть тут - http://testsite482.vacau.com/Site.html

Соответственно вопрос по этому же примеру. Есть основной массив текста. И есть кусок с автором цитаты. По какой-то неведомой для меня причине, я не могу этот кусок, с подписью, поставить по центру прямо под цитатой. Точнее могу, но перестает работать скрипт.

В чем может быть проблема?

G
На сайте с 22.11.2013
Offline
2
#1

Или даже немного изменю вопрос. Можете помочь, и подсказать, как осуществить задумку?

maggotinaff
На сайте с 13.09.2012
Offline
10
#2

Проблема в том, что replace потерла тег <p align="center">...</p>, соотв-но нет центрирования. Можно решить так:

1) Основной текст заворачиваем тоже в тег <p>...</p>


<div id="example">
<p>Here’s to the crazy ones. The misfits. The rebels. The
troublemakers. The round pegs in the square holes. The ones who see things differently. They’re not fond of rules.
And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them.
About the only thing you can’t do is ignore them. Because they change things. They push the human race forward.
While some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they
can change the world, are the ones who do.</p>
<p align="center">Steve Jobs</p></div>

2) Немного правим скрипт и применяем его не ко всему блоку, а к вложенным параграфам $('#example p').animate_Text():


<script type="text/javascript">
$(document).ready(function(){
$.fn.animate_Text = function() {
return this.each(function(){
var $this = $(this);
var string = $this.text();
$this.html(string.replace(/./g, '<span class="new">$&</span>'));
$this.find('span.new').each(function(i, el){
setTimeout(function(){ $(el).addClass('div_opacity'); }, 97 * i);
});
});
};
$('#example').show();
$('#example p').animate_Text();
});
</script>

Тогда все заменится правильно.

стабильный доход (http://fx-trend.com/landing/pamm1?agent=502515) уже 2+ года
G
На сайте с 22.11.2013
Offline
2
#3
maggotinaff:
Проблема в том, что replace потерла тег <p align="center">...</p>, соотв-но нет центрирования. Можно решить так:

1) Основной текст заворачиваем тоже в тег <p>...</p>

<div id="example">
<p>Here’s to the crazy ones. The misfits. The rebels. The
troublemakers. The round pegs in the square holes. The ones who see things differently. They’re not fond of rules.
And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them.
About the only thing you can’t do is ignore them. Because they change things. They push the human race forward.
While some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they
can change the world, are the ones who do.</p>
<p align="center">Steve Jobs</p></div>


2) Немного правим скрипт и применяем его не ко всему блоку, а к вложенным параграфам $('#example p').animate_Text():

<script type="text/javascript">
$(document).ready(function(){
$.fn.animate_Text = function() {
return this.each(function(){
var $this = $(this);
var string = $this.text();
$this.html(string.replace(/./g, '<span class="new">$&</span>'));
$this.find('span.new').each(function(i, el){
setTimeout(function(){ $(el).addClass('div_opacity'); }, 97 * i);
});
});
};
$('#example').show();
$('#example p').animate_Text();
});
</script>


Тогда все заменится правильно.

Да, но в таком случае, получается, что одновременно начинает выводится основной текст и подпись. А хочется, что бы вывелся текст, и сразу после него, через одну строчку по середине так же выплыла надпись с автором цитаты. То есть, последовательно, а не одновременно. Это как-то можно сделать?) Уж пардон за такие нубские вопросы, только начинаю осваивать все это дело)

maggotinaff
На сайте с 13.09.2012
Offline
10
#4

Да, <p></p> так и оставляем, а код примерно такой:


<script type="text/javascript">
$(document).ready(function(){
$.fn.animate_Text = function() {
return this.each(function(){
var $this = $(this);
var string = $this.text();
$this.children().each(function(){
var el = $(this);
var string = el.text();
el.html(string.replace(/./g, '<span class="new">$&</span>'));
})
$this.find('span.new').each(function(i, el){
setTimeout(function(){ $(el).addClass('div_opacity'); }, 97 * i);
});
});
};
$('#example').show();
$('#example').animate_Text();
});
</script>
G
На сайте с 22.11.2013
Offline
2
#5

Огромное спасибо! Все именно так, как должно быть!

Если не сильно отвлекаю, еще один маленький вопрос? Возможно как-то задать, что бы этот скрипт начинал работать спустя 5 секунд после загрузки страницы? Что бы текст появлялся более-менее равномерно со звуком.

maggotinaff
На сайте с 13.09.2012
Offline
10
#6

Как говорят у нас работе: "JS-ом можно даже колбасу резать" :D

Там где непосредственно вызов скрипта просто добавляете задержку:


setTimeout(function(){
$('#example').show();
$('#example').animate_Text();
},5000);
G
На сайте с 22.11.2013
Offline
2
#7

Чудно, все работает) Еще раз огромное спасибо)

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий