0

寻找可用于创建与此示例相同的垂直“图像平移”/“鼠标悬停”效果的代码,用于以下WordPress 主题全屏图像

您的回复表示赞赏。

谢谢

4

2 回答 2

0

这是一种方法的一些伪代码。

css
.div{
width:200px;
height:200px;
overflow:hidden;
}

jQuery
$('#theimage').mousemove(function(event){
    $('#theimage').css('top', function(current){
        return current + event.pageY + offset; 
        //offset is what sets the zero point in the center
        };
});

从中得出的结论应该是逻辑而不是代码本身。我还没有尝试过,我很确定可能仍然存在错误。

于 2013-01-22T08:12:28.503 回答
0

试试这个代码 div 有一个大的 backgroundimage ,大于它的宽度和高度

// HTML

<div id="pageBg">
</div>

//CSS

#pageBg {
    background: url(images/pageBg.jpg) no-repeat 0 0 scroll;
    background-size: cover;
    height: auto;
    left: 0;
    min-height: 768px;
    min-width: 1024px;
    overflow: hidden;
    position: fixed;   
    top: 0;
    width: 100%;
}

// Javascript

$(document).ready(function(){
   $('#pageBg').mousemove(function(e){
      var mousePosY = (e.pageY/$(window).width())*100;
      $('#pageBg').css('background-position-y', mousePosY +'%');
   }); 
});
于 2013-01-23T20:48:29.810 回答