Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="chaimg" data="2.jpg,3.jpg" style="background: url('1.jpg'); height: 160px; background-size: cover;"></div>
- $(function() {
- $('.chaimg').hover(function() {
- var _this = this,
- images = _this.getAttribute('data').split(',');
- counter = 0;
- this.css('background', 'url("'+this.src+'")');
- _this.timer = setInterval(function() {
- if(counter > images.length) {
- counter = 0;
- }
- _this.src=images[counter];
- counter++;
- }, 500);
- }, function() {
- this.src = this.css("background");
- clearInterval(this.timer);
- });
- });
- $('.video-item-thumb').on({
- mouseenter: function () {
- theImage = $(this).attr('id');
- otherImages = $(this).attr('data').split(',');
- rotateThumbs(otherImages, theImage);
- },
- mouseleave:function () {
- for (var i = 1; i < 99999; i++)
- window.clearInterval(i);
- }
- }, '.chaimg');
- function rotateThumbs(otherImages, theImage) {
- var i = 0;
- var interval = setInterval(function() {
- $('#'+theImage).css('background', 'url("'+otherImages[i++]+'")');
- if (i >= otherImages.length) {
- i = 0;
- }
- }, 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement