Skip to content

haptics

NPM version

Platform Support

Platform Support

介绍:

振动插件

Reference

Method

  • impactLight

    触碰轻质量物体

ts
import { 
hapticsPlugin
,
ImpactStyle
} from "@plaoc/plugins";
await
hapticsPlugin
.
impactLight
({
style
:
ImpactStyle
.
Heavy
});
  • notification

    振动通知

ts
import { 
hapticsPlugin
,
NotificationType
} from "@plaoc/plugins";
await
hapticsPlugin
.
notification
({
type
:
NotificationType
.
Success
});
  • vibrateClick

    单击手势的反馈振动

ts
import { 
hapticsPlugin
} from "@plaoc/plugins";
await
hapticsPlugin
.
vibrateClick
();
  • vibrateDisabled

    禁用手势的反馈振动

ts
import { 
hapticsPlugin
} from "@plaoc/plugins";
await
hapticsPlugin
.
vibrateDisabled
();
  • vibrateDoubleClick

    双击手势的反馈振动

ts
import { 
hapticsPlugin
} from "@plaoc/plugins";
await
hapticsPlugin
.
vibrateDoubleClick
();
  • vibrateHeavyClick

    重击手势的反馈振动, 比如菜单键/惨案/3Dtouch

ts
import { 
hapticsPlugin
} from "@plaoc/plugins";
await
hapticsPlugin
.
vibrateHeavyClick
();
  • vibrateTick

    滴答

ts
import { 
hapticsPlugin
} from "@plaoc/plugins";
await
hapticsPlugin
.
vibrateTick
();
  • vibrate

    自定义效果

ts
import { 
hapticsPlugin
, VibrateOptions } from "@plaoc/plugins";
await
hapticsPlugin
.
vibrate
({
duration
: [100, 200, 300] });

Parameter

  • ImpactStyle

    触碰反馈强度

ts
import { 
ImpactStyle
} from "@plaoc/plugins";
ImpactStyle
.
Heavy
;
  • NotificationType

    通知类型

ts
import { 
NotificationType
} from "@plaoc/plugins";
NotificationType
.
Success
;
  • VibrateOptions

    振动频率

ts
import { VibrateOptions } from "@plaoc/plugins";

const 
options
: VibrateOptions = {
duration
: [100, 1, 200] };

Usage Plugins

vue
<script setup lang="ts">
import { 
hapticsPlugin
} from "@plaoc/plugins";
async function
customVibrate
() {
await
hapticsPlugin
.
vibrate
({
duration
: [10, 2, 100, 3, 10] });
} </script>

Usage WebComponent

vue
<script setup lang="ts">
import { 
ref
} from "vue";
import {
HTMLDwebHapticsElement
} from "@plaoc/plugins";
const
$hapticsPlugin
=
ref
<
HTMLDwebHapticsElement
>();
let
haptics
:
HTMLDwebHapticsElement
;
onMounted(async () => {
haptics
=
$hapticsPlugin
.
value
!;
}); async function
customVibrate
() {
haptics
.
vibrate
({
duration
: [10, 2, 100, 3, 10] });
} </script> <template> <
dweb-haptics
ref
="
$hapticsPlugin
"></
dweb-haptics
>
</template>

基于 MIT 许可发布