2012-09-26 111 views
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> 

的問題是文字淡出,但很好用閃光燈重新出現。任何方式我都可以使淡入淡出。

回答

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/

一個項目顯示的時間,並顯示項目淡出然後下一項消失。

+0

我相信你已經有了一些樣式,所以這是我個人的享受比任何東西更多,但看看:http://jsfiddle.net/ffe6q/5/ – Shmiddty

+0

這是非常好的。謝謝 – Jawad

4

相反的:

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

做這樣的事情:

$(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000); 
2

檢查FIDDLE

function tick() { 
    $('#ticker li:first').animate({ 
     'opacity': 0 
    },2000, function() { 
     $(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000); 
    }); 
} 
setInterval(function() { 
    tick() 
}, 8000);​ 
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的

+0

注:如果孩子( ':第一胎')不舒爾實際上要快比孩子()第一。 (),前一段時間有一些測試,但沒有找到它們atm。 – Simon

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); 
0

變量$股票= $( '#股票');

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

功能打勾(){

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

    $(this).appendTo($ticker); 

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

}); 

} 的setInterval(打勾,8000)