css3 marquee

HTML结构如下:

<div class="marquee"><div><span>marquee标签拥有很多的动效,可惜遭到HTML5废弃,本文利用css3模拟其水平滚动效果。</span></div></div>

原本一层DIV足够,又加了一层是为了增加左右的空白间隙。

然后就可以应用transform动画了:

.marquee {
    height: 36px;
    line-height: 36px;
    color: #f90;
    background-color: #ffc;
    border-top: 1px solid #f2f2f2;
    border-bottom: 1px solid #f2f2f2;
    box-sizing: border-box;
    word-break: break-all;
    white-space: nowrap;

    div {
        margin: 0 10px;
        overflow: hidden;
    }

    span {
        display: inline-block;
        padding-left: 100%;  /* 从右至左开始轮播 */
        -webkit-animation: marquee 16s linear infinite;
        animation: marquee 16s linear infinite;
    }
    span:hover { /* 鼠标点击时暂停轮播 */
        -webkit-animation-play-state: paused;
        animation-play-state: paused;
    }
}

/* Make it move */
@-webkit-keyframes marquee {
    0%   { -webkit-transform: translate(0, 0); }
    100% { -webkit-transform: translate(-100%, 0); }
}
@keyframes marquee {
    0%   { transform: translate(0, 0); }
    100% { transform: translate(-100%, 0); }
}

方案源于stackoverflow:css3-marquee-effect

转载于:https://my.oschina.net/u/2324376/blog/714173

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值