0

ホバー時の画像の背景位置を垂直方向と水平方向の両方で変更しようとしていますが、次のコードは機能しません。何か案は?

CSS :

#background-thing{ 
    background: url(http://www.dnitza.com/experiments/fullscreen-pan/stairway.jpg) no-repeat 0 0 scroll; 
    background-size: cover; 
    height: auto;
    left: 0;
    min-height: 100%;
    min-width: 1024px;
    overflow: hidden;
    position: fixed;
    top: 0;
    width: 100%;
} 

Jクエリ

$('#background-thing').mousemove(function(e){
    var mousePosX = (e.pageX/$(window).width())*100;
    var mousePosY = (e.pageY/$(window).height())*100;
    $('#background-thing').css('backgroundPosition', mousePosX+'%' + mousePosY);
}); 
4

1 に答える 1

3

スペースと % がありません

$('#background-thing').css('backgroundPosition', mousePosX +'% '+mousePosY+'%');

フィドル

于 2013-10-01T13:43:34.563 に答える