javascript - 知道什么时候位置: sticky div is stuck without jQuery

标签 javascript jquery html css

我正在开发 Angular 元素的移动优先 UI,其中 position: sticky 的 div 需要更改其样式,因此如何仅在 div 卡住后才将样式应用于 div,而不使用 jQuery 等.

我试过使用 https://developers.google.com/web/updates/2016/04/intersectionobserver 但我无法模拟该功能

.title {
  font-size: 16px;
  color: black;
}


/*On being stuck*/

.title
/*::stuck*/

{
  font-size: 18px;
  background: grey;
}
<div style="height: 700px;">
  <div class="title" style="position: sticky; position: -webkit-sticky; top: 20px;">
    This div is to be styled on being 'stuck'
  </div>
</div>

最佳答案

<script>
    position = document.getElementsByClassName("title")[0].style.position;
    result = position === 'sticky';
    console.log(result);
</script>

关于javascript - 知道什么时候位置: sticky div is stuck without jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56951807/

相关文章:

javascript - 如何在 100% 的 body 上扩展一个子 div 而不是一个具有动态宽度的父 div

javascript - 区域范围图例图标与标记不匹配

javascript - 编辑注册表单 woocommerce 中的字段类型

jquery - Bootstrap 进度条

javascript - 我的 jquery 语法和格式有什么问题?

javascript - 将对象键值与数组中的值进行匹配

javascript - 通过 JavaScript 调用 Bootstrap Accordion

HTML5 Canvas - 放大一个点

javascript - 如何从一个 html 文件加载所有 CSS 和 JS?

html - 从底部和右侧移除框阴影