Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function Animation(elem){
  2. // code tests the application of js arrow function
  3. // date August 18, 2018
  4. this.elemid = document.querySelector('#'+elem)
  5. }
  6. Animation.prototype = {
  7. constructor: Animation,
  8. color: ['red', 'blue', 'black', 'yellow'],
  9. display:function(){
  10. var len = this.color.length;
  11. var index = 0;
  12. setInterval(()=>{
  13. if(index < len){this.elemid.style.backgroundColor = this.color[index];
  14. index++;
  15. }else{
  16. index =0;
  17. this.elemid.style.backgroundColor = this.color[index]
  18. }
  19.  
  20. },3000);
  21. }
  22. };
  23. var testDiv = new Animation('test');// create instance of the class
  24. testDiv.display();
  25. var test2 = new Animation('test2');// create another instance
  26. test2.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement