Skip to content

NoticeBar Scrolling Notice Component ​

This component is used for scrolling announcement scenarios, supporting multiple modes such as horizontal scrolling, vertical scrolling, and stepped scrolling.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

⚠️ Notes ​

Notes

  • The text parameter supports a string or array format; an array is recommended for carousel scrolling
  • url and mode="link" must be set together to enable page navigation
  • The step property only takes effect when direction="row", enabling stepped scrolling
  • The disableTouch property currently only supports App 2.5.5+, H5 2.5.5+, Alipay Mini Program, and ByteDance Mini Program

🏯 Basic Usage Examples ​

Basic Usage ​

html
<template>
    <hy-notice-bar text="Welcome to the Hy Component Library"></hy-notice-bar>
</template>

Array Content ​

html
<template>
    <hy-notice-bar :text="textList"></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['Ji-ji, and ji-ji again,', 'Mulan weaves at her door.', 'No sound of loom or shuttle,', 'Only the maiden sighs.']);
</script>

Closable Mode ​

html
<template>
    <hy-notice-bar :text="textList" mode="closable"></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['This is a closable notice', 'Click the close button on the right to hide the notice']);
</script>

Custom Scroll Speed ​

html
<template>
    <hy-notice-bar :text="textList" :speed="150"></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['Scroll speed is 150px/s', 'The larger the value, the faster the scrolling']);
</script>
html
<template>
    <hy-notice-bar text="Click to view details" mode="link" url="/pages/detail/index"></hy-notice-bar>
</template>

Custom Navigation Type ​

html
<template>
    <hy-notice-bar
        text="Go to home page"
        mode="link"
        url="/pages/index/index"
        link-type="switchTab"
    ></hy-notice-bar>
</template>

Horizontal Stepped Scrolling ​

html
<template>
    <hy-notice-bar :text="textList" step></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['First notice', 'Second notice', 'Third notice']);
</script>

Vertical Scrolling ​

html
<template>
    <hy-notice-bar :text="textList" direction="column"></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['First vertical scrolling notice', 'Second vertical scrolling notice', 'Third vertical scrolling notice']);
</script>

Custom Style ​

html
<template>
    <hy-notice-bar
        text="Notice with custom colors"
        color="#ff5722"
        bg-color="#fff3e0"
        :font-size="16"
    ></hy-notice-bar>
</template>

Custom Icon ​

html
<template>
    <hy-notice-bar
        text="Using a custom icon"
        :icon="{
            name: IconConfig.SCAN,
            color: 'red'
        }"
    ></hy-notice-bar>

    <hy-notice-bar text="Using a custom icon" :icon="IconConfig.SCAN"></hy-notice-bar>
</template>

Text Alignment ​

html
<template>
    <!-- Left aligned -->
    <hy-notice-bar text="Left aligned" justify-content="flex-start"></hy-notice-bar>

    <!-- Center aligned -->
    <hy-notice-bar text="Center aligned" justify-content="center"></hy-notice-bar>

    <!-- Right aligned -->
    <hy-notice-bar text="Right aligned" justify-content="flex-end"></hy-notice-bar>
</template>

Disable Touch Swiping ​

html
<template>
    <hy-notice-bar :text="textList" direction="column" :disable-touch="false"></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['Supports gesture swiping to switch', 'Swipe up or down to switch notices']);
</script>

Listening to Events ​

html
<template>
    <hy-notice-bar
        :text="textList"
        mode="closable"
        @click="handleClick"
        @close="handleClose"
    ></hy-notice-bar>
</template>

<script setup>
    import { reactive } from 'vue';

    const textList = reactive(['Clicking a notice triggers an event', 'Closing a notice also triggers an event']);

    const handleClick = (index) => {
        uni.showToast({
            title: `Clicked notice No. ${index + 1}`,
            icon: 'none',
        });
    };

    const handleClose = () => {
        uni.showToast({
            title: 'Notice closed',
            icon: 'none',
        });
    };
</script>

API ​

NoticeBar Props ​

ParameterDescriptionTypeDefault
textContent to display, supports a string or arraystring|string[]-
directionScroll mode: row-horizontal scrolling, column-vertical scrollingrow | columnrow
stepWhen direction = row, whether to use stepped scrollingbooleanfalse
iconWhether to show the left icon; accepts an icon name or icon configuration objectstring|HyIconPropsNOTIFICATION_FILL
modeNotice mode: link-shows right arrow, closable-shows right close iconlink | closable-
colorText color; the icon also uses this colorstring#ff9900
bgColorBackground colorstring-
speedScroll speed for horizontal scrolling, i.e., pixels scrolled per second; the larger the value, the faster the scrollingnumber80
fontSizeFont size; numeric values use px by defaultstring | number14
durationTime for one scroll cycle, in msnumber2000
disableTouchWhether to disable swipe switching; only supported on App 2.5.5+, H5 2.5.5+, Alipay Mini Program, and ByteDance Mini Programbooleantrue
urlPage path to navigate tostring-
linkTypePage navigation type; optional values: navigateTo, redirectTo, switchTab, reLaunchstringnavigateTo
justifyContentHorizontal layout type of the text; optional values: flex-start, center, flex-endstringflex-start
customStyleCustom outer stylesCSSProperties-
customClassCustom outer class namestring-

Events ​

Event NameDescriptionCallback Parameters
clickTriggered when the notice text is clickedindex: index of the currently displayed text
closeTriggered when the right close icon is clicked-

CSS Variables ​

Variable NameDescriptionDefault Value
--hy-notice-bar-paddingInner padding9px 12px
--hy-notice-bar-bgBackground color#fff6c8
--hy-notice-bar-font-sizeText font size14px
--hy-notice-bar-swiper-heightVertical scrolling line height16px
--hy-notice-bar-radiusNotice bar border radiusFollows --hy-radius-sm (8rpx)
12:33
battery