Vibrate

Vibrate the device with a given pattern and duration.

Usage

<script>
    import { vibrate } from "@sveu/browser"

    const { supported, start, stop } = vibrate()
</script>
<script>
    import { vibrate } from "@sveu/browser"

    const { supported, start, stop } = vibrate()
</script>
svelte

Example

Your can't use this feature.

<script>
    import { useragent, vibrate } from "@sveu/browser"

    const { supported, start, stop } = vibrate()

    const { mobile } = useragent()
</script>

<div class="flex flex-col w-full items-center">
    {#if $supported && $mobile}
        <button
            on:click="{start}"
            >Start</button>

        <br />

        <button
            on:click="{stop}"
            >Stop</button>
    {:else}
        <h1>Your can't use this feature.</h1>
    {/if}
</div>
<script>
    import { useragent, vibrate } from "@sveu/browser"

    const { supported, start, stop } = vibrate()

    const { mobile } = useragent()
</script>

<div class="flex flex-col w-full items-center">
    {#if $supported && $mobile}
        <button
            on:click="{start}"
            >Start</button>

        <br />

        <button
            on:click="{stop}"
            >Stop</button>
    {:else}
        <h1>Your can't use this feature.</h1>
    {/if}
</div>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Click fold/expand code

API

Options

Name Description Type Default
pattern Vibration Pattern in seconds number[] or number []
interval Interval to run a persistent vibration, in seconds number 0


Returns

Name Description Type
supported Whether the browser supports the Vibration API boolean
intervalControls Controls for the persistent vibration Pauseable
start Start the vibration () => void
stop Stop the vibration () => void