Skip to content

Overlay Component

Creates an overlay to emphasize specific page elements and prevent users from interacting with content beneath the overlay, typically used in modal scenarios

📌Platform Differences

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 transparency of the overlay, 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

Arbitrary content can be embedded on the overlay through the default slot

Note

If you don't want click events on 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 4th rgba parameternumber0.5
LockScrollv0.6.4Whether to lock page scrollingbooleantrue
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
clickEmitted when the overlay is clicked-

Slots

Slot NameDescriptionReceived Value
defaultDefault slot, used to embed content on top of the overlay-
03:29