1

I am working on a mobile first UI of an Angular project, where the div which is position: sticky needs to change its style, so how can I apply styling to the div only after it is stuck, without using jQuery, etc.

I've tried using https://developers.google.com/web/updates/2016/04/intersectionobserver but I am not able to mock that functionality

.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>
shrys
  • 5,635
  • 2
  • 20
  • 32
  • If you're asking for a pseudo selector, it [isn't possible yet](https://stackoverflow.com/a/25312347/4051471) – shrys Jul 09 '19 at 11:51
  • If you know how to do it with JQuery, you can use [this website](http://youmightnotneedjquery.com/) to convert it to plain JS – Cristian Traìna Jul 09 '19 at 12:49

1 Answers1

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