2020-08-13 11:47:56 +08:00
|
|
|
|
<template>
|
|
|
|
|
<article class="anchor-offset-demo">
|
|
|
|
|
<div class="target-offset-line"/>
|
|
|
|
|
<div class="sticky-offset-line"/>
|
|
|
|
|
<div
|
|
|
|
|
ref="container"
|
|
|
|
|
class="anchor-wrapper"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-for="i in coffees"
|
|
|
|
|
:id="i.value.indexOf('#') >= 0 ? i.value.slice(1) : i.value"
|
|
|
|
|
:key="i.value"
|
|
|
|
|
class="block"
|
|
|
|
|
>
|
|
|
|
|
{{ i.label }}
|
|
|
|
|
</div>
|
|
|
|
|
<section class="anchor-two">
|
|
|
|
|
<h3>吸附锚点</h3>
|
|
|
|
|
<veui-anchor
|
|
|
|
|
:items="coffees"
|
|
|
|
|
target-offset="20px"
|
|
|
|
|
sticky-offset="30px"
|
|
|
|
|
container="container"
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { Anchor } from 'veui'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
'veui-anchor': Anchor
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
coffees: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Infused',
|
2021-09-16 19:23:58 +08:00
|
|
|
|
value: '#infused1',
|
2020-08-13 11:47:56 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Breadcrumb',
|
|
|
|
|
value: '/components/breadcrumb'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Boiled',
|
2021-09-16 19:23:58 +08:00
|
|
|
|
value: '#boiled1',
|
2020-08-13 11:47:56 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Button',
|
|
|
|
|
value: '/components/button'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Espresso',
|
2021-09-16 19:23:58 +08:00
|
|
|
|
value: '#espresso1'
|
2020-08-13 11:47:56 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Milk coffee',
|
2021-09-16 19:23:58 +08:00
|
|
|
|
value: '#milk-coffee1'
|
2020-08-13 11:47:56 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-09-15 20:03:51 +08:00
|
|
|
|
<style lang="less" scoped>
|
2020-08-13 11:47:56 +08:00
|
|
|
|
.anchor-offset-demo {
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
.sticky-offset-line,
|
|
|
|
|
.target-offset-line {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 20px;
|
|
|
|
|
width: 180px;
|
2021-09-15 20:03:51 +08:00
|
|
|
|
border-top: 1px solid red;
|
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
|
&::after {
|
2021-09-16 19:23:58 +08:00
|
|
|
|
content: "targetOffset(切换于此)";
|
2020-08-13 11:47:56 +08:00
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
color: red;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-15 20:03:51 +08:00
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
|
.sticky-offset-line {
|
|
|
|
|
top: 30px;
|
|
|
|
|
left: 250px;
|
2021-09-15 20:03:51 +08:00
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
|
&::after {
|
2021-09-16 19:23:58 +08:00
|
|
|
|
content: "stickyOffset(吸附于此)";
|
2020-08-13 11:47:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.anchor-wrapper {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
height: 300px;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
border: 1px dashed;
|
|
|
|
|
|
|
|
|
|
& > section {
|
|
|
|
|
position: absolute;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.block {
|
|
|
|
|
white-space: nowrap;
|
2021-09-16 19:23:58 +08:00
|
|
|
|
border-top: 1px solid #000;
|
2020-08-13 11:47:56 +08:00
|
|
|
|
width: 100px;
|
|
|
|
|
height: 150px;
|
|
|
|
|
flex: none;
|
2021-09-15 20:03:51 +08:00
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
|
& + .block {
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-15 20:03:51 +08:00
|
|
|
|
|
2020-08-13 11:47:56 +08:00
|
|
|
|
.anchor-two {
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: 250px;
|
|
|
|
|
top: 50px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<docs>
|
2021-09-16 19:23:58 +08:00
|
|
|
|
虚线框标记容器,黑实线标记锚点项顶部。
|
|
|
|
|
|
|
|
|
|
当黑实线和 `tagetOffset` 线重合触发激活。
|
|
|
|
|
|
|
|
|
|
`Anchor` 吸附在 `stickyOffset` 线处。
|
2020-08-13 11:47:56 +08:00
|
|
|
|
</docs>
|