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

FIDDLEを確認してください

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

It would be easier and more concise if you used the jQuery effects .fadeIn(time_in_ms) & .fadeOut(time_in_ms). More info here: http://api.jquery.com/fadeIn/ & http://api.jquery.com/fadeOut/.

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

于 2012-09-26T22:22:59.077 に答える
1

How about this?

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

jsfiddle based on susanth reddy's

于 2012-09-26T22:23:36.270 に答える
1

I think what you want is something more like this:

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/

One item is shown at a time, and the displayed item fades out then the next item fades in.

于 2012-09-26T22:47:32.157 に答える
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(ティック、8000)

于 2013-10-07T12:12:17.353 に答える