我有以下标记。
<ul id="ticker">
<li><q> Education, then, beyond all other devices of human origin, is the great equalizer of the conditions of men, the balance-wheel of the social machinery </q><cite>Horace Mann</cite></li>
<li><q> The roots of education are bitter, but the fruit is sweet </q><cite>Aristotle</cite></li>
<li><q> Education is what remains after one has forgotten everything he learned in school </q><cite>Albert Einstein</cite></li>
<li><q> Education is the most powerful weapon which you can use to change the world </q><cite>Nelson Mandela</cite></li>
<li><q> Formal education will make you a living; self-education will make you a fortune </q><cite>Jim Rohn</cite></li>
</ul>
以下脚本
<script>
function tick()
{
$('#ticker li:first').animate({'opacity':0}, 2000, function () { $(this).appendTo($('#ticker')).css('opacity', 1); });
}
setInterval(function(){ tick () }, 8000);
</script>
问题是文字很好地淡出但是用闪光灯重新出现。我可以用任何方式使淡入淡出。
答案 0 :(得分:4)
而不是:
$(this).appendTo($('#ticker')).css('opacity', 1);
做类似的事情:
$(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
答案 1 :(得分:2)
检查FIDDLE
function tick() {
$('#ticker li:first').animate({
'opacity': 0
},2000, function() {
$(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
});
}
setInterval(function() {
tick()
}, 8000);
答案 2 :(得分:1)
如果你使用jQuery效果.fadeIn(time_in_ms)
&amp;将会更简单,更简洁。 .fadeOut(time_in_ms)
。更多信息:http://api.jquery.com/fadeIn/&amp; http://api.jquery.com/fadeOut/
示例:$('#ticker li:first').fadeIn(1000);
答案 3 :(得分:1)
这个怎么样?
var $ticker = $('#ticker'); // save the static element
function tick(){
$ticker.children().first().fadeOut(2000, function () {
$(this).appendTo($ticker).fadeIn(500);
});
}
setInterval(tick, 8000);
jsfiddle基于susanth reddy的
答案 4 :(得分:1)
我认为你想要的更像是这样:
var $ticker = $('#ticker'); // save the static element
$ticker.children(':not(:first-child)').hide();
function tick(){
$ticker.children(':first-child').fadeOut(1000, function () {
$(this).appendTo($ticker);
$ticker.children().first().fadeIn(1000);
});
}
setInterval(tick, 8000);
一次显示一个项目,显示的项目淡出然后下一个项目淡入。
答案 5 :(得分:1)
如果您正在尝试制作幻灯片,我就想到了这一点。 css:
ul{position: relative;}
li{position: absolute;}
li:not(:first-child){display: none;}
和js:
function tick(){
$('#ticker > li:first').fadeOut(1000).next().fadeIn(1000).end().appendTo('#ticker');
}
setInterval(function(){ tick () }, 8000);
答案 6 :(得分:0)
var $ ticker = $('#ticker');
$ ticker.children( ':否(:第一子)')。隐藏();
function tick(){
$ticker.children(':first-child').fadeOut(1000, function () {
$(this).appendTo($ticker);
$ticker.children().first().fadeIn(1000);
});
} setInterval(tick,8000)