Skip to content

Commit 2582591

Browse files
committed
fix: bug
1 parent 42f95ce commit 2582591

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/components/post/SideAd.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Positioner = styled.div`
1919
const AdBlock = styled.div<{ width: number; height: number }>`
2020
width: ${(props) => props.width}px;
2121
height: ${(props) => props.height}px;
22-
// background: #e0e0e0;
22+
background: #e0e0e0;
2323
// border-radius: 4px;
2424
display: flex;
2525
// color: #666;
@@ -68,7 +68,7 @@ export default function SideAd() {
6868

6969
const onScroll = useCallback(() => {
7070
const scrollTop = getScrollTop();
71-
const nextFixed = scrollTop + 112 + 142 > y;
71+
const nextFixed = scrollTop + 242 > y;
7272
if (fixed !== nextFixed) {
7373
setFixed(nextFixed);
7474
}
@@ -81,8 +81,9 @@ export default function SideAd() {
8181
userAgent,
8282
);
8383
const hasMinWidth = window.innerWidth >= 1200;
84+
const hasMinHeight = window.innerHeight >= 674;
8485

85-
setIsDesktop(!isMobile && hasMinWidth);
86+
setIsDesktop(!isMobile && hasMinWidth && hasMinHeight);
8687

8788
// Set mode based on window height
8889
const windowHeight = window.innerHeight;
@@ -91,7 +92,7 @@ export default function SideAd() {
9192

9293
useEffect(() => {
9394
setup();
94-
}, [setup]);
95+
}, [setup, mode]);
9596

9697
useEffect(() => {
9798
window.addEventListener('scroll', onScroll);
@@ -103,7 +104,21 @@ export default function SideAd() {
103104
useEffect(() => {
104105
const handleResize = () => {
105106
const windowHeight = window.innerHeight;
107+
const windowWidth = window.innerWidth;
108+
109+
// Update mode based on height
106110
setMode(windowHeight < 864 ? 'mini' : 'regular');
111+
112+
// Update isDesktop based on width and height
113+
const userAgent = navigator.userAgent.toLowerCase();
114+
const isMobile =
115+
/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(
116+
userAgent,
117+
);
118+
const hasMinWidth = windowWidth >= 1200;
119+
const hasMinHeight = windowHeight >= 674;
120+
121+
setIsDesktop(!isMobile && hasMinWidth && hasMinHeight);
107122
};
108123

109124
window.addEventListener('resize', handleResize);

0 commit comments

Comments
 (0)