Skip to content

Commit f3188a2

Browse files
committed
feat: add image viewer transition
1 parent 770cba9 commit f3188a2

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/plugin-image-viewer/src/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
right: 0;
66
bottom: 0;
77
z-index: 10000;
8-
background-color: rgba(0, 0, 0, 0.7);
8+
background-color: rgba(0, 0, 0, 0.8);
9+
transition: opacity 200ms;
910
}
1011
.image-viewer img {
1112
position: absolute;

packages/plugin-image-viewer/src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,22 @@ export default function imageViewer(): BytemdPlugin {
3737
img.style.left = `${left}px`;
3838
img.style.top = `${top}px`;
3939

40-
const container = document.createElement('div');
41-
container.className = 'image-viewer';
42-
container.appendChild(img);
40+
const box = document.createElement('div');
41+
box.className = 'image-viewer';
42+
box.style.opacity = '0';
43+
box.appendChild(img);
4344

44-
document.body.appendChild(container);
45+
document.body.appendChild(box);
4546

46-
container.addEventListener('click', (e) => {
47-
document.body.removeChild(container);
47+
setTimeout(() => {
48+
box.style.opacity = '1';
49+
});
50+
51+
box.addEventListener('click', (e) => {
52+
box.addEventListener('transitionend', () => {
53+
document.body.removeChild(box);
54+
});
55+
box.style.opacity = '0';
4856
});
4957
};
5058

0 commit comments

Comments
 (0)