mirror of
https://github.com/element-plus/element-plus.git
synced 2025-03-07 15:47:57 +08:00
fix(components): [anchor] scroll whether link is selected at the top (#18047)
fix(components): [anchor] Scroll whether link is selected at the top Co-authored-by: sea <45450994+warmthsea@users.noreply.github.com> Co-authored-by: btea <2356281422@qq.com>
This commit is contained in:
parent
8b829ea7d3
commit
bd5c07ea72
@ -60,6 +60,13 @@ export const anchorProps = buildProps({
|
||||
type: definePropType<'vertical' | 'horizontal'>(String),
|
||||
default: 'vertical',
|
||||
},
|
||||
/**
|
||||
* @description Scroll whether link is selected at the top
|
||||
*/
|
||||
scrollTop: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
export type AnchorProps = ExtractPropTypes<typeof anchorProps>
|
||||
|
@ -134,13 +134,12 @@ const getCurrentHref = () => {
|
||||
})
|
||||
}
|
||||
anchorTopList.sort((prev, next) => prev.top - next.top)
|
||||
|
||||
for (let i = 0; i < anchorTopList.length; i++) {
|
||||
const item = anchorTopList[i]
|
||||
const next = anchorTopList[i + 1]
|
||||
|
||||
if (i === 0 && scrollTop === 0) {
|
||||
return ''
|
||||
return props.scrollTop ? item.href : ''
|
||||
}
|
||||
if (item.top <= scrollTop && (!next || next.top > scrollTop)) {
|
||||
return item.href
|
||||
|
Loading…
Reference in New Issue
Block a user