mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
fixed slide block transitions
This commit is contained in:
parent
d06593b4cb
commit
f837924ad4
3 changed files with 56 additions and 47 deletions
|
@ -76,7 +76,13 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
if (!wrap || !wrap.current) return;
|
if (!wrap || !wrap.current) return;
|
||||||
|
|
||||||
const { width } = wrap.current.getBoundingClientRect();
|
const { width } = wrap.current.getBoundingClientRect();
|
||||||
|
|
||||||
const selected = Math.abs(-offset / width);
|
const selected = Math.abs(-offset / width);
|
||||||
|
|
||||||
|
if (is_loading) {
|
||||||
|
return setHeight((width * 9) / 16);
|
||||||
|
}
|
||||||
|
|
||||||
const prev = Math.max(heights[Math.floor(selected)] || 320, 320);
|
const prev = Math.max(heights[Math.floor(selected)] || 320, 320);
|
||||||
const next = Math.max(heights[Math.ceil(selected)] || 320, 320);
|
const next = Math.max(heights[Math.ceil(selected)] || 320, 320);
|
||||||
const now = prev - (prev - next) * (selected % 1);
|
const now = prev - (prev - next) * (selected % 1);
|
||||||
|
@ -84,7 +90,7 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
if (current !== Math.round(selected)) setCurrent(Math.round(selected));
|
if (current !== Math.round(selected)) setCurrent(Math.round(selected));
|
||||||
|
|
||||||
setHeight(now);
|
setHeight(now);
|
||||||
}, [offset, heights, max_height, images]);
|
}, [wrap, offset, heights, max_height, images, is_loading]);
|
||||||
|
|
||||||
const onDrag = useCallback(
|
const onDrag = useCallback(
|
||||||
event => {
|
event => {
|
||||||
|
@ -107,6 +113,8 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
);
|
);
|
||||||
|
|
||||||
const normalizeOffset = useCallback(() => {
|
const normalizeOffset = useCallback(() => {
|
||||||
|
if (!slide.current || !wrap.current) return;
|
||||||
|
|
||||||
const { width: wrap_width } = wrap.current.getBoundingClientRect();
|
const { width: wrap_width } = wrap.current.getBoundingClientRect();
|
||||||
const { width: slide_width } = slide.current.getBoundingClientRect();
|
const { width: slide_width } = slide.current.getBoundingClientRect();
|
||||||
|
|
||||||
|
@ -175,18 +183,16 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
[wrap]
|
[wrap]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_loading) {
|
|
||||||
return (
|
|
||||||
<div className={styles.placeholder}>
|
|
||||||
<div>
|
|
||||||
<LoaderCircle size={96} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(styles.wrap, { is_loading })} ref={wrap}>
|
<div className={classNames(styles.wrap, { is_loading })} ref={wrap}>
|
||||||
|
{is_loading && (
|
||||||
|
<div className={styles.placeholder}>
|
||||||
|
<div>
|
||||||
|
<LoaderCircle size={96} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<ImageSwitcher
|
<ImageSwitcher
|
||||||
total={images.length}
|
total={images.length}
|
||||||
current={current}
|
current={current}
|
||||||
|
@ -197,7 +203,6 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
<div
|
<div
|
||||||
className={styles.image_container}
|
className={styles.image_container}
|
||||||
style={{
|
style={{
|
||||||
transition: is_dragging ? 'none' : 'transform 500ms',
|
|
||||||
height,
|
height,
|
||||||
transform: `translate(${offset}px, 0)`,
|
transform: `translate(${offset}px, 0)`,
|
||||||
width: `${images.length * 100}%`,
|
width: `${images.length * 100}%`,
|
||||||
|
@ -206,24 +211,25 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
||||||
onTouchStart={startDragging}
|
onTouchStart={startDragging}
|
||||||
ref={slide}
|
ref={slide}
|
||||||
>
|
>
|
||||||
{images.map((file, index) => (
|
{!is_loading &&
|
||||||
<div
|
images.map((file, index) => (
|
||||||
className={classNames(styles.image_wrap, {
|
<div
|
||||||
is_active: index === current && loaded[index],
|
className={classNames(styles.image_wrap, {
|
||||||
})}
|
is_active: index === current && loaded[index],
|
||||||
ref={setRef(index)}
|
})}
|
||||||
key={file.id}
|
ref={setRef(index)}
|
||||||
>
|
|
||||||
<img
|
|
||||||
className={styles.image}
|
|
||||||
src={getURL(file, PRESETS['1400'])}
|
|
||||||
alt=""
|
|
||||||
key={file.id}
|
key={file.id}
|
||||||
onLoad={onImageLoad(index)}
|
>
|
||||||
style={{ maxHeight: max_height }}
|
<img
|
||||||
/>
|
className={styles.image}
|
||||||
</div>
|
src={getURL(file, PRESETS['1400'])}
|
||||||
))}
|
alt=""
|
||||||
|
key={file.id}
|
||||||
|
onLoad={onImageLoad(index)}
|
||||||
|
style={{ maxHeight: max_height }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
will-change: transform, height;
|
will-change: transform, height;
|
||||||
|
transition: height 500ms, transform 500ms;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
|
||||||
.image {
|
.image {
|
||||||
max-height: 960px;
|
max-height: 960px;
|
||||||
|
@ -44,22 +49,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.placeholder {
|
.placeholder {
|
||||||
padding-bottom: 66%;
|
position: absolute;
|
||||||
position: relative;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
& > div {
|
top: 0;
|
||||||
position: absolute;
|
left: 0;
|
||||||
width: 100%;
|
display: flex;
|
||||||
height: 100%;
|
align-items: center;
|
||||||
top: 0;
|
justify-content: center;
|
||||||
left: 0;
|
background: $content_bg;
|
||||||
display: flex;
|
z-index: 1;
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
opacity: 0.025;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
opacity: 0.025;
|
||||||
fill: white;
|
fill: white;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,15 +107,17 @@ function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
|
||||||
data: { node, error },
|
data: { node, error },
|
||||||
} = yield call(reqWrapper, getNode, { id });
|
} = yield call(reqWrapper, getNode, { id });
|
||||||
|
|
||||||
yield put(nodeSetLoading(false));
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return yield put(nodeSetSaveErrors({ error }));
|
yield put(nodeSetSaveErrors({ error }));
|
||||||
|
yield put(nodeSetLoading(false));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(nodeSetSaveErrors({}));
|
yield put(nodeSetSaveErrors({}));
|
||||||
yield put(nodeSetCurrent(node));
|
yield put(nodeSetCurrent(node));
|
||||||
|
|
||||||
|
yield put(nodeSetLoading(false));
|
||||||
|
|
||||||
const {
|
const {
|
||||||
comments: {
|
comments: {
|
||||||
data: { comments },
|
data: { comments },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue