Skip to content

Overlay Component ​

Create an overlay to emphasize specific page elements and prevent users from interacting with content beneath the overlay. Commonly used in popup scenarios.

📌 Platform Compatibility ​

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

🏯 Basic Usage Examples ​

html
<!-- Global usage -->
<hy-overlay :show="show" @click="show = false"></hy-overlay>
ts
import { ref } from 'vue';

const show = ref(true);

Setting Opacity ​

  • Set the opacity value to adjust the overlay's opacity, with a range of 0~1
html
<template>
    <hy-overlay :show="show" :opacity="0.1"></hy-overlay>
    <hy-overlay :show="show" :opacity="0.9"></hy-overlay>
</template>

Custom Slots ​

You can embed any content on the overlay through the default slot

Note

If you don't want the click event of the slot content to bubble up to the overlay, add @tap.stop to the specified element

html
<template>
    <hy-overlay :show="show" @click="show = false">
        <view class="warp">
            <view class="rect" @tap.stop></view>
        </view>
    </-overlay>
</template>

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

    const show = ref(true);
</script>

<style lang="sass" scoped>
    .warp {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
    }

    .rect {
        width: 120px;
        height: 120px;
        background-color: #fff;
    }
</style>

API ​

Overlay Props ​

ParameterDescriptionTypeDefault
showWhether to show the overlaybooleanfalse
zIndexz-index levelnumber10070
durationAnimation duration, in millisecondsnumber300
opacityOpacity value, used as the fourth parameter of rgbanumber0.5
LockScrollv0.6.4Whether to lock page scrollingbooleantrue
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback Parameters
clickTriggered when the overlay is clicked-

Slots ​

Slot NameDescriptionAccepted Values
defaultDefault slot, used to embed content on top of the overlay-

CSS Variables ​

Variable NameDescriptionDefault Value
--hy-overlay-bgOverlay background colorrgba(0, 0, 0, 0.7)
12:33
battery