Проблемы с animate и backgroundPosition
http://demo.en.cx/GameDetails.aspx?gid=15736 - блок "От автора игры" с параллакс-скроллингом.
$(function(){ $('head').append('<link href="http://d2.endata.cx/data/games/15736/prison.css" type="text/css" rel="stylesheet" />'); enter = false; var skof = $('#skof'); var link = $('#link'); var fon = $('#fon'); var opis = $('#opis'); opis.live('mousemove', function(e) { var offset = opis.offset(); var curX = (e.pageX - offset.left); var smar = 70-Math.round(curX/11); var t = 20*Math.abs(parseInt(skof.css('marginLeft'))-smar); if (t==0 || enter==true) { enter = true; skof.css('marginLeft', smar); link.css('marginLeft', 319-smar); fon.css('backgroundPosition', (smar*(-1.4))); } else { skof.stop(true).animate({ marginLeft: smar }, t); link.stop(true).animate({ marginLeft: 319-smar }, t); fon.stop(true).animate({ backgroundPosition: smar*(-1.4) }, t); } }).live('mouseleave', function() { enter = false; var smar = skof.css('marginLeft'); var t = parseInt(smar)*20; skof.stop(true).animate({ marginLeft: 0 }, t); link.stop(true).animate({ marginLeft: 319 }, t); fon.stop(true).animate({ backgroundPosition: 0 }, t); }).live('mouseenter', function() { skof.stop(true); link.stop(true); fon.stop(true); }); }) В ИЕ8 при событии mouseleave анимация: fon.stop(true).animate({ backgroundPosition: 0 }, t); выполняется мгновенно, в то время как остальные двигающиеся части: skof.stop(true).animate({ marginLeft: 0 }, t); link.stop(true).animate({ marginLeft: 319 }, t); Выполняются за время равное t |
fon.stop(true).animate({ backgroundPosition: "0 0" }, t); |
Эффекта ноль. Что интересно, к этому элементу уже применяется подобная анимация в событии mouseenter.
|
Цитата:
к ней стандартно не применяется анимация jquery только в конце анимации ставится значение, например '0 0' |
если это свойство разделить на два и анимировать по-отдельности (пр. код), то анимируется нормально.
$("div").animate({backgroundPositionX:"150px", backgroundPositionY:"150px"},{duration:'slow'}); |
css свойство background-position-x и background-position-y не везде работает http://htmlbook.ru/css/background-position-y
|
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script> <style type="text/css"> div { background-image: url('http://javascript.ru/forum/image.php?u=12584&dateline=1310044212'); width: 80px; height: 80px; } </style> </head> <body> <div></div> <script type="text/javascript"> $(function(){ $("div").animate({backgroundPositionX:"150px", backgroundPositionY:"150px"},{duration:3000}); }); </script> </body> </html> |
а можно короче, используя параметр step
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.min.js"></script> <style> div { background-image: url('http://javascript.ru/forum/image.php?u=12584&dateline=1310044212'); width: 80px; height: 80px; } </style> </head> <body> <div></div> <script> $(function(){ $("div").animate({backgroundPositionMy:150},{duration:3000, step: function (n) { $(this).css('background-position', n + 'px ' + n + 'px'); }}); }); </script> </body> </html> |
Часовой пояс GMT +3, время: 04:17. |