Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentinel stops working when the DOM element has css animation-name defined #4

Open
tnhu opened this issue Sep 18, 2017 · 5 comments
Open
Labels

Comments

@tnhu
Copy link

tnhu commented Sep 18, 2017

This is a super neat technique. Except when the DOM element has animation-name rule defined, it stops working.

https://jsfiddle.net/tnhu/1u146utg/2/

@amorey
Copy link
Member

amorey commented Sep 18, 2017

Thanks for checking! There's a work around for this but I hadn't added it to the documentation yet.

To get around this problem you can pass an extra animation name to the on() method:

sentinel.on('.my-div', function(el) {
  // add an input box
  var inputEl = document.createElement('input');
  el.appendChild(inputEl);
}, 'anim1, anim2');

https://github.com/muicss/sentineljs/blob/master/README.md#on---add-a-watch-for-new-dom-nodes

@amorey
Copy link
Member

amorey commented Sep 21, 2017

I've added more details about this to the README:
https://github.com/muicss/sentineljs/blob/master/README.md#introduction

Marking this as Issue as archived.

@amorey
Copy link
Member

amorey commented Sep 24, 2017

@tnhu I added an option to trigger a SentinelJS watch function from CSS by defining a custom animation event name (v0.0.3):

<style>
  @keyframes slidein {
    from: {margin-left: 100%;}
    to: {margin-left: 0%;}
  }

  .my-div {
    animation-duration: 3s;
    animation-name: slide-in, node-inserted;
  }
</style>
<script>
  // trigger on "node-inserted" animation event name (using "!" prefix)
  sentinel.on('!node-inserted', function(el) {
    el.insertHTML = 'The sentinel is always watching.';
  });
</script>

Here's an update to your JSFiddle that fixes the issue:
https://jsfiddle.net/muicss/25nus53b/2/

Hope that helps! Let me know you have any thoughts or suggestions.

@amorey amorey mentioned this issue Sep 24, 2017
@lxjwlt
Copy link

lxjwlt commented Sep 28, 2017

is that means we could only detect animation-name instead of element selector when it has animation-name rule defined?

@amorey
Copy link
Member

amorey commented Sep 28, 2017

@lxjwlt In this scenario, the CSS selector is defined by the CSS rule where animation-name is being used. In other words, both of these code snippets will detect .my-div:

<script>
  sentinel.on('.my-div', function(el) {
    el.insertHTML = 'The sentinel is always watching.';
  });
</script>
<style>
  @keyframes slidein {
    from: {margin-left: 100%;}
    to: {margin-left: 0%;}
  }

  .my-div {
    animation-duration: 3s;
    animation-name: slide-in, node-inserted;
  }
</style>
<script>
  // trigger on "node-inserted" animation event name (using "!" prefix)
  sentinel.on('!node-inserted', function(el) {
    el.insertHTML = 'The sentinel is always watching.';
  });
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants