美文网首页
新闻跑马灯效果

新闻跑马灯效果

作者: web_newbie | 来源:发表于2018-02-27 14:59 被阅读0次

1.纯css实现:
html代码:

<div class="marquee">
        <div>
            <span>You spin me right round, baby. Like a record, baby.</span>
            <span>You spin me right round, baby. Like a record, baby.</span>
        </div>
    </div>

css代码如下:

        .marquee{
            position:relative;
            width:420px;
            height:25px;
            overflow:hidden;
        }
        .marquee div{
            position:absolute;
            top:0;left:0;
            width:200%;
            height:30px;
            overflow:hidden;
            animation:marquee 5s linear infinite;
        }
        .marquee div span{
            float:left;
            width:50%;
        }
        @keyframes marquee{
            0% {left:0;}
            5% {left:0;}
            100% {left:-100%;}
        }

PS:属于投机取巧,具体情况自行选择;
2.用jquery插件(jquery.marquee):

       ul,li {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        ul.marquee {
            display: block;
            line-height: 1;
            position: relative;
            overflow: hidden;
            width: 400px;
            height: 22px;
        }

        ul.marquee li {
            position: absolute;
            top: -999em;
            left: 0;
            display: block;
            white-space: nowrap;
            padding: 3px 5px;
            text-indent: 0.8em
        }

html示例:

    <div>
        <ul id="marquee" class="marquee">
            <li>You spin me right round, baby.</li>
            <li>You spin me right round, baby. Like a record</li>
        </ul>
    </div>

js 示例:

<script src="./jquery.min.js"></script>
<script src="lib/jquery.marquee.js"></script>
<script>
    $('#marquee').marquee({yScroll:"bottom"})
</script>

PS:跑马灯结构必须要用ul与li,且需要定位;
marquee有很多default options,可以根据需要修改
注:

{
          yScroll: "top"                          // the position of the marquee initially scroll (can be either "top" or "bottom")
        , showSpeed: 850                          // the speed of to animate the initial dropdown of the messages
        , scrollSpeed: 12                         // the speed of the scrolling (keep number low)
        , pauseSpeed: 5000                        // the time to wait before showing the next message or scrolling current message
        , pauseOnHover: true                      // determine if we should pause on mouse hover
        , loop: -1                                // determine how many times to loop through the marquees (#'s < 0 = infinite)
        , fxEasingShow: "swing"                   // the animition easing to use when showing a new marquee
        , fxEasingScroll: "linear"                // the animition easing to use when showing a new marquee

        // define the class statements
        , cssShowing: "marquee-showing"

        // event handlers
        , init: null                              // callback that occurs when a marquee is initialized
        , beforeshow: null                        // callback that occurs before message starts scrolling on screen
        , show: null                              // callback that occurs when a new marquee message is displayed
        , aftershow: null                         // callback that occurs after the message has scrolled
    }

相关文章

网友评论

      本文标题:新闻跑马灯效果

      本文链接:https://www.haomeiwen.com/subject/lbvpxftx.html