Skip to content

Commit e3a6669

Browse files
committed
Larger draggable area
Signed-off-by: Yukai Huang <[email protected]>
1 parent 82253f4 commit e3a6669

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

public/js/lib/renderer/lightbox/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ function addImageZoomListener (container) {
131131
function addImageDragListener (image) {
132132
let moved = false
133133
let pos = []
134-
image.addEventListener('mousedown', (evt) => {
134+
135+
const container = findOrCreateLightboxContainer()
136+
const inner = container.querySelector('.lightbox-inner')
137+
138+
const onMouseDown = (evt) => {
135139
moved = true
136140

137141
const { left, top } = image.getBoundingClientRect()
@@ -140,27 +144,32 @@ function addImageDragListener (image) {
140144
evt.pageX - left,
141145
evt.pageY - top
142146
]
143-
}, true)
147+
}
148+
image.addEventListener('mousedown', onMouseDown)
149+
inner.addEventListener('mousedown', onMouseDown)
144150

145-
image.addEventListener('mousemove', (evt) => {
151+
const onMouseMove = (evt) => {
146152
if (!moved) {
147153
return
148154
}
149155

150156
image.style.left = `${evt.pageX - pos[0]}px`
151157
image.style.top = `${evt.pageY - pos[1]}px`
152158
image.style.position = 'absolute'
153-
}, true)
159+
}
160+
image.addEventListener('mousemove', onMouseMove)
161+
inner.addEventListener('mousemove', onMouseMove)
154162

155-
image.addEventListener('mouseup', () => {
163+
const onMouseUp = () => {
156164
moved = false
157165
pos = []
158-
}, true)
166+
}
167+
image.addEventListener('mouseup', onMouseUp)
168+
inner.addEventListener('mouseup', onMouseUp)
159169

160-
image.addEventListener('mouseout', () => {
161-
moved = false
170+
inner.addEventListener('click', (e) => {
171+
e.stopPropagation()
162172
})
163-
164173
image.addEventListener('click', (e) => {
165174
e.stopPropagation()
166175
})

public/js/lib/renderer/lightbox/lightbox.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@
7272
right: 10px;
7373
}
7474

75+
.lightbox-container .lightbox-inner {
76+
width: 100%;
77+
height: 100%;
78+
cursor: move;
79+
80+
display: -webkit-box;
81+
display: -webkit-flex;
82+
display: -moz-box;
83+
display: -ms-flexbox;
84+
85+
display: flex;
86+
-webkit-box-align: center;
87+
-webkit-align-items: center;
88+
-moz-box-align: center;
89+
-ms-flex-align: center;
90+
align-items: center;
91+
-webkit-box-pack: center;
92+
-webkit-justify-content: center;
93+
-moz-box-pack: center;
94+
-ms-flex-pack: center;
95+
justify-content: center;
96+
}
97+
7598
.lightbox-container .lightbox-inner img {
7699
max-width: 100%;
77100
cursor: move;

0 commit comments

Comments
 (0)