鸿蒙应用开发marquee跑马灯效果实现 原创

鸿蒙时代
发布于 2021-4-25 09:42
浏览
0收藏

marquee的案例

 

一个跑马灯的效果,我们可以通过按钮控制跑马灯速度,方向,次数,是否流动等操作。

鸿蒙应用开发marquee跑马灯效果实现-鸿蒙开发者社区

  

 

Html代码如下:

<div class="container">
    <marquee id="marquee_lianxi" class="customMarquee" scrollamount="{{shudu}}" loop="{{loop}}"direction="{{chuchang}}" onbounce="onMarqueeBounce" onstart="onMarqueeStart" onfinish="onMarqueeFinish">{{marqueeCustomData}}</marquee>
    <div class="content">
        <button class="controlButton" onclick="you">右出</button>
        <button class="controlButton" onclick="zhuo">左出</button>
    </div>
    <marquee id="customMarquee" class="customMarquee" scrollamount="{{scrollAmount}}" loop="{{loop}}"direction="{{marqueeDir}}" onbounce="onMarqueeBounce" onstart="onMarqueeStart" onfinish="onMarqueeFinish">{{marqueeCustomData}}</marquee>
    <div class="content">
        <button class="controlButton" onclick="onStartClick">Start</button>
        <button class="controlButton" onclick="onStopClick">Stop</button>
    </div>
</div>

Css代码如下:

.container {
    flex-direction: column;
    align-items: center;
    background-color: #ffffff;
}
.customMarquee {
    width: 100%;
    height: 80px;
    padding: 10px;
    margin: 20px;
    border: 4px solid #ff8888;
    border-radius: 20px;
    font-size: 40px;
    color: #ff8888;
    font-weight: bolder;
    font-family: serif;
    background-color: #ffdddd;
}
.content {
    flex-direction: row;
    width: 300px;
    height: 120px;
}
.controlButton {
    flex-grow: 1;
    width: 300px;
    height: 120px;
}

Js代码如下:

export default {
    data: {
        scrollAmount: 20,
        loop: true,
        marqueeDir: 'left',
        marqueeCustomData: '富强、民主、文明、和谐, 自由、平等、公正、法治, 爱国、敬业、诚信、友善、',
        shudu: 30,
        chuchang : 'right',
        shudu_show:50,
    },
    onMarqueeBounce: function() {
        console.log("onMarqueeBounce");
    },
    onMarqueeStart: function() {
        console.log("onMarqueeStart");
    },
    onMarqueeFinish: function() {
        console.log("onMarqueeFinish");
    },
    onStartClick (evt) {
        this.$element('customMarquee').start();
    },
    onStopClick (evt) {
        this.$element('customMarquee').stop();
    },
    zhuo (evt) {
        this.chuchang = 'right'
    },
    you (evt) {
        this.chuchang = 'left'
    }
}

完整代码地址:

https://gitee.com/jltfcloudcn/jump_to/tree/master/JS_marquee

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
标签
已于2021-4-30 17:25:24修改
1
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
鸿蒙时代
鸿蒙时代

https://harmonyos.51cto.com/show/4131

1
回复
2021-4-25 11:20:48
回复
    相关推荐