图像平移效果 - 垂直 - 鼠标悬停

时间:2013-01-22 07:48:57

标签: javascript jquery wordpress panning

寻找可用于为以下in this example创建与WordPress themes full screen images相同的垂直'图像平移'/'鼠标悬停'效果的代码

您的回复表示赞赏。

由于

2 个答案:

答案 0 :(得分: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
        };
});

这应该是逻辑,而不是代码本身。我没试过,很确定可能还有错误。

答案 1 :(得分:0)

试试这段代码 div具有大的背景图像,大于其宽度和高度

// 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 +'%');
   }); 
});
相关问题