0

我有以下标记。

<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>

问题是文本很好地淡出,但会随着闪光灯重新出现。任何方式我都可以使淡入淡出也顺利。

4

7 回答 7

4

代替:

$(this).appendTo($('#ticker')).css('opacity', 1);

执行以下操作:

$(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
于 2012-09-26T22:18:05.147 回答
2

检查小提琴

function tick() {
    $('#ticker li:first').animate({
        'opacity': 0
    },2000, function() {
        $(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
    });
}
setInterval(function() {
    tick()
}, 8000);​
于 2012-09-26T22:21:19.887 回答
1

如果你使用 jQuery 效果.fadeIn(time_in_ms)&会更容易和更简洁.fadeOut(time_in_ms)。更多信息在这里:http ://api.jquery.com/fadeIn/ & http://api.jquery.com/fadeOut/

例子:$('#ticker li:first').fadeIn(1000);

于 2012-09-26T22:22:59.077 回答
1

这个怎么样?

var $ticker = $('#ticker'); // save the static element
function tick(){
    $ticker.children().first().fadeOut(2000, function () {
        $(this).appendTo($ticker).fadeIn(500);
    });
}
setInterval(tick, 8000);

基于 susanth reddy 的jsfiddle

于 2012-09-26T22:23:36.270 回答
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);

http://jsfiddle.net/ffe6q/3/

一次显示一个项目,显示的项目淡出然后下一个项目淡入。

于 2012-09-26T22:47:32.157 回答
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);
于 2013-10-06T02:09:55.947 回答
0

var $ticker = $('#ticker');

$ticker.children(':not(:first-child)').hide();

功能滴答(){

$ticker.children(':first-child').fadeOut(1000, function () {

    $(this).appendTo($ticker);

    $ticker.children().first().fadeIn(1000);

});

} setInterval(tick, 8000)

于 2013-10-07T12:12:17.353 回答