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 - 测试异步运行时如何使用 sinon 沙箱?

javascript - 实现模态工厂?

javascript - 将图像属性更改为<li>示例标题</>

java - 将网站的 <div> 解析为 webview

javascript - 类型错误 : is not a function

javascript - jquery .attr和.prop删除Chrome中的属性

javascript - jquery内部的 Angular 函数需要双击才能调用

javascript - .on jquery 方法和动态创建的按钮

php - 在php中上传带有图像的表单

javascript - 单击按钮的 Chrome 扩展程序