Skip to content

Commit af75998

Browse files
committed
fix: Message 鼠标移入清除定时器 移出重置定时器
1 parent 534dfe5 commit af75998

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib/message/src/message.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
'is-close': close,
1616
'is-center': center,
1717
}"
18+
@mouseenter="clearTimer"
19+
@mouseleave="startTimer"
1820
>
1921
<jw-icon
2022
class="jw-message-icon"
@@ -75,19 +77,26 @@ const props = defineProps(messageProps);
7577
const emits = defineEmits(messageEmits);
7678
7779
const visible = ref(false);
80+
let stopTimer = undefined;
81+
7882
const customStyle = computed(() => ({
7983
top: `${props.offset}px`,
8084
zIndex: props.zIndex,
8185
}));
8286
8387
function startTimer() {
8488
if (props.duration > 0) {
85-
setTimeout(() => {
89+
stopTimer = setTimeout(() => {
8690
if (visible.value) close();
8791
}, props.duration);
8892
}
8993
}
9094
95+
function clearTimer() {
96+
clearTimeout(stopTimer);
97+
stopTimer = undefined;
98+
}
99+
91100
function close() {
92101
visible.value = false;
93102
}

0 commit comments

Comments
 (0)