Skip to content

Instantly share code, notes, and snippets.

@senthilp
Last active April 24, 2017 23:31
Show Gist options
  • Save senthilp/5ffcc4370f86da04ab89dcec42531c7a to your computer and use it in GitHub Desktop.
Save senthilp/5ffcc4370f86da04ab89dcec42531c7a to your computer and use it in GitHub Desktop.
class MyCarousel extends HTMLElement {
static get observedAttributes() {
return ['index'];
}
// Called anytime the 'index' attribute is changed
attributeChangedCallback(attrName, oldVal, newVal) {
this[attrName] = newVal;
}
// Takes an index value
set index(idx) {
// First check if it is numeric
const numericIndex = parseInt(idx, 10);
if (isNaN(numericIndex)) {
return;
}
// Update the internal state
this._index = numericIndex;
/* Perform the associated DOM operations */
moveCarousel();
}
get index() {
return this._index;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment