Created
October 1, 2016 19:25
-
-
Save kolyasademetrio/3e2d99047cc5bd2a47db568cec952ef0 to your computer and use it in GitHub Desktop.
JS: вращающаяся фотография при наведении
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initPhotoHover(){ | |
var avatar = $(".photo"); | |
var cycleTimer = ""; | |
function cyclePhoto(photo){ | |
var position = photo.css('background-position').split(' '); | |
if (parseInt(position[1],10) == -photo.outerWidth()*7) { photo.css('background-position', '0 0'); } | |
else { photo.css('background-position', position[0] + ' ' + (parseInt(position[1],10) - photo.outerWidth()) + 'px'); } | |
} | |
$.each(avatar, function(){ | |
var photo = $(this); | |
photo.on("mouseover", function(){ cycleTimer = setInterval(function(){ cyclePhoto(photo); }, 100); }); | |
photo.on("mouseleave", function(){ clearInterval(cycleTimer); }); | |
}); | |
} | |
$(document).ready(function(){ initPhotoHover(); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment