IntersectionObserver.relativeToViewport

解释:指定页面显示区域作为参照区域之一

方法参数

Object object

margins参数说明: 用来扩展(或收缩)参照节点布局区域的边界

示例

在开发者工具中预览效果

扫码体验

请使用百度APP扫码

图片示例

代码示例

  1. <scroll-view class="scroll-view" scroll-y> <view class="scroll-area" style="{{appear ? 'background: #ccc' : ''}}"> <text class="notice">向下滚动让小球出现</text> <!-- 占位元素 --> <view class="filling"></view> <!-- 小球 --> <view class="ball"></view> </view></scroll-view>
  1. Page({
  2. data: { },
  3. onReady() {
  4. const intersectionObserver = swan.createIntersectionObserver(this);
  5. intersectionObserver
  6. .relativeToViewport({bottom: 100})
  7. console.log(intersectionObserver) // {selector: null, margins: {bottom: 100}}
  8. swan.showModal({
  9. title: 'relativeToViewport',
  10. content: JSON.stringify(intersectionObserver._relativeInfo)
  11. });
  12. },
  13. onUnload() {
  14. this.intersectionObserver && this.intersectionObserver.disconnect();
  15. }
  16. });