-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: The step element does not highlight on scrollIntoViewOptions: { … #67
base: master
Are you sure you want to change the base?
fix: The step element does not highlight on scrollIntoViewOptions: { … #67
Conversation
…behavior: 'smooth'} #50509
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough此次更改在 Changes
Sequence Diagram(s)(不适用,未生成序列图因为变化过于简单。) Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/hooks/useTarget.ts (1 hunks)
Additional comments not posted (3)
src/hooks/useTarget.ts (3)
45-55
: 封装位置计算逻辑的实现很好!
calculatePosition
函数将位置计算逻辑封装起来,提高了代码的可读性和可维护性。
60-71
: 使用 IntersectionObserver 优化视图更新逻辑!使用
IntersectionObserver
来观察目标元素的可见性,并在元素进入视图时触发位置计算,这是一个很好的改进。300 毫秒的延迟有助于确保滚动完成。
73-77
: 确保在组件挂载和窗口调整大小时更新位置。在
useLayoutEffect
中调用updatePos
确保了在必要时重新计算位置,并且在组件卸载时移除事件监听器,保证了资源的正确释放。
Fixed the highlight bug when the scroll behavior was smooth
Summary by CodeRabbit
IntersectionObserver
来改善目标元素的可见性处理,使得位置更新更为高效和响应。