функция задержки не работает с каждым.
то, что я делаю, - это когда пользователь нажимает кнопку закрытия, сначала затухает всплывающее окно, а затем удаляет атрибут стиля из всех li.
проблема - это затухание до того, как popup fadeout атрибут style активирует действие, поэтому я использовал задержку для замедления события removeAttr. но получить некоторые проблемы с кодом..
в одной из статей, которую я читал, чтобы использовать индекс, каждый из них пытался, но все еще не получал проблем.
jQuery('.clsbb').click(function(){
jQuery('.new-rows').fadeOut(3000);
jQuery('.products li').each(function(index){
jQuery(this).delay(1000 * index).removeAttr('style');
});
});
<div class="clsbb">close</div>
<ul>
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li class="new-rows">popup</li>
</ul>
нужна помощь для всплывающего окна fadeout, затем removeAttr
Используйте complete
аргумент в fadeout
:
jQuery('.new-rows').fadeOut(3000, function(){
// this code will be called after the animation completes
jQuery('.products li').removeAttr('style');
});
[править] полное решение:
<div class="clsbb">close</div>
<ul class="products">
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li style="margin-top:10px;">row2</li>
<li class="new-rows">popup</li>
</ul>
jQuery('.clsbb').click(function () {
jQuery('.new-rows').fadeOut(3000, function () {
jQuery('.new-rows').remove();
jQuery('.products li').removeAttr('style');
});
});
Вы можете добиться этого с помощью методов обратного вызова:
jQuery('.new-rows').fadeOut(3000, function(){
// Use callback method.
jQuery('.products li').removeAttr('style'); // Not sure why you have used 1000 * index. Use it here as well if required.
});
Редактировать, как Джек Торрис jQuery('.products li').removeAttr('style');
это удалит стиль из всех li, а не только один. Но если вы все еще хотите использовать.each
jQuery('.new-rows').fadeOut(3000, function(){
// Use callback method.
jQuery('.products li').each ( function(){ $(this).removeAttr('style'); } );
});
jQuery('.products li').removeAttr('style');
Products jQuery('.products li').removeAttr('style');
это будет удалить стиль из всех литий не только один. Но если вы все еще хотите использовать .each, посмотрите мой отредактированный ответ.