Skip to content

Instantly share code, notes, and snippets.

@kolyasademetrio
Created October 1, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolyasademetrio/3e2d99047cc5bd2a47db568cec952ef0 to your computer and use it in GitHub Desktop.
Save kolyasademetrio/3e2d99047cc5bd2a47db568cec952ef0 to your computer and use it in GitHub Desktop.
JS: вращающаяся фотография при наведении
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