Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <div class="chaimg" data="2.jpg,3.jpg" style="background: url('1.jpg'); height: 160px; background-size: cover;"></div>
  2.  
  3. $(function() {
  4. $('.chaimg').hover(function() {
  5. var _this = this,
  6. images = _this.getAttribute('data').split(',');
  7. counter = 0;
  8. this.css('background', 'url("'+this.src+'")');
  9.  
  10. _this.timer = setInterval(function() {
  11. if(counter > images.length) {
  12. counter = 0;
  13. }
  14. _this.src=images[counter];
  15.  
  16. counter++;
  17. }, 500);
  18.  
  19. }, function() {
  20. this.src = this.css("background");
  21. clearInterval(this.timer);
  22. });
  23. });
  24.  
  25. $('.video-item-thumb').on({
  26. mouseenter: function () {
  27. theImage = $(this).attr('id');
  28. otherImages = $(this).attr('data').split(',');
  29. rotateThumbs(otherImages, theImage);
  30.  
  31. },
  32. mouseleave:function () {
  33. for (var i = 1; i < 99999; i++)
  34. window.clearInterval(i);
  35. }
  36.  
  37. }, '.chaimg');
  38.  
  39.  
  40. function rotateThumbs(otherImages, theImage) {
  41. var i = 0;
  42. var interval = setInterval(function() {
  43. $('#'+theImage).css('background', 'url("'+otherImages[i++]+'")');
  44. if (i >= otherImages.length) {
  45. i = 0;
  46. }
  47. }, 1000);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement