spz-interact-observer
Layouts
跳转到“Layouts”Usage
跳转到“Usage”<header id="header">
<!-- ... --->
</header>
<spz-interact-observer
layout="container"
target-id="header"
distance="50"
to="header.hide;"
from="header.show;"
></spz-interact-observer>
<div id="rely-id" style="position: sticky; top: 0; height: 50px;">
<h1>Announcement</h1>
</div>
<!-- The `to` will be set to 60px(50px + 10px) -->
<div id="target-id" style="position: absolute; top: 10px;">
<h3>Heading Three Level</h3>
</div>
<spz-interact-observer
layout="container"
target-id="target-id"
rely-id="rely-id"
rely-sticky
></spz-interact-observer>
Attributes
跳转到“Attributes”target-id
跳转到“target-id”required
Specifies a the id of the target element. Apply some behavior to the target element.
observe-id
跳转到“observe-id”The element ID to be observed.
rely-id
跳转到“rely-id”A DOM id of the dependent element. If this attribute is present, it will set the target element’s top attribute to the height of the rely-id element plus the previous top attribute’s value.
If the height of the rely-id element is 81px. The previous top attribute’s value is 20px, the top value will be set to 101px.
rely-sticky
跳转到“rely-sticky”If this attribute is present, it only takes effect when the dependent element is a sticky layout. It must be used with the rely-id or the observe-id.
rely-offsetTop
跳转到“rely-offsetTop”If this attribute is present, get the offset position of the target element as the distance from to switch from to to. It must be used with the from or the to.
interact
跳转到“interact”It has the following values:
scrolldefaultmousemove: Triggered when the mouse moves.
from
跳转到“from”Specify some behavior that needs to be performed when the condition is met.
to
跳转到“to”Specifies some behavior that needs to be reverted when the condition is not met.
distance
跳转到“distance”Specifies a distance to change. If the distance of the scroll is greater than the distance value, the to attribute will be executed. Otherwise, the from attribute will be executed.
smoothness
跳转到“smoothness”Smoothness parameter. Its value is 30
Actions
跳转到“Actions”change
跳转到“change”No parameter required. To change the top of the element. It must be used with the rely-id attribute.
stickyChange
跳转到“stickyChange”No parameter required. To change the top or bottom attribute of the element when it is the sticky of the position. It must be used with the to, the to value is to="position: top;" or to="position: bottom;".
Events
跳转到“Events”change
跳转到“change”Be automatically triggered when the change action is called.