Created
November 15, 2011 09:14
-
-
Save bbrodriges/1366532 to your computer and use it in GitHub Desktop.
Наложение картинки на картинку с прозрачностью (не тестировалось)
This file contains hidden or 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
//Предположим, что картинка находится в диве ( <div class="myimage"><img src="/images/old-image.png"></div> ) | |
$('div.myimage').hover( | |
function(){ //при наведении мыши | |
var sourceImg = $('div.myimage img').attr('src'); //забираем урл картинки | |
$('div.myimage img').attr('/images/new-image.png').css({opacity: 0.5}); //вставляем новую картинку и накладываем прозрачность 50% | |
$(this).css('background-image', sourceImg); //делаем оригинальную картинку фоном дива | |
}, | |
function(){ //при уходе мыши | |
var sourceImg = $(this).css('background-image'); //забираем урл старой картинки | |
$('div.myimage img').attr(sourceImg).css({opacity: 1}); //вставляем старую картинку и возвращаем прозрачность | |
$(this).css('background-image', 'none'); //убираем фон | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment