首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >控制淡入淡出的动画

控制淡入淡出的动画
EN

Stack Overflow用户
提问于 2012-09-27 06:14:55
回答 7查看 537关注 0票数 0

我有以下标记。

代码语言:javascript
复制
<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>

和下面的脚本

代码语言:javascript
复制
<script>
function tick()
{
$('#ticker li:first').animate({'opacity':0}, 2000, function () { $(this).appendTo($('#ticker')).css('opacity', 1); });
}
setInterval(function(){ tick () }, 8000);
</script>

问题是,文本淡出得很好,但会在闪光中重新出现。任何方式,我可以使淡入也平滑。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2012-09-27 06:47:32

我认为你想要的东西更像这样:

代码语言:javascript
复制
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/

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

票数 1
EN

Stack Overflow用户

发布于 2012-09-27 06:18:05

而不是:

代码语言:javascript
复制
$(this).appendTo($('#ticker')).css('opacity', 1);

做一些类似的事情:

代码语言:javascript
复制
$(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
票数 4
EN

Stack Overflow用户

发布于 2012-09-27 06:21:20

检查FIDDLE

代码语言:javascript
复制
function tick() {
    $('#ticker li:first').animate({
        'opacity': 0
    },2000, function() {
        $(this).appendTo($('#ticker')).animate({'opacity' : 1}, 2000);
    });
}
setInterval(function() {
    tick()
}, 8000);​
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12611269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档