【发布时间】:2017-04-27 00:16:14
【问题描述】:
作为我之前的问题here 的后续,我尝试在页面的两侧制作悬停图像。
JS:
var movementStrength = 25;
var w = $(window).width();
var h = $(window).height();
$(window).mousemove(function(e){
var pageX = (e.pageX - w / 2) / w / 2;
var pageY = (e.pageY - h / 2) / h / 2;
var newvalueX = pageX * movementStrength;
var newvalueY = pageY * movementStrength;
$('.top-image-left').css({ left: newvalueX + 'px', top: newvalueY + 'px'});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='top-contain-left'>
<div class="top-image-left">
</div>
</div>
<div class='top-contain-right'>
<div class="top-image-right"></div>
</div>
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='top-contain-left'>
<div class="top-image-left">
</div>
</div>
<div class='top-contain-right'>
<div class="top-image-right"></div>
</div>
CSS:
.top-contain-left {
padding: 25px;
width: 35%;
height: 35%;
position: absolute;
top: 400px;
}
.top-image-left {
background: url('http://i.imgur.com/wZRaMrB.png');
position: absolute;
background-size: contain;
width: 100%;
z-index: 0;
height: 100%;
background-repeat: no-repeat;
}
.top-contain-right {
padding:25px;
width:35%;
height:35%;
position:absolute;
top:400px;
right: -20%;
}
.top-image-right {
background:url('http://i.imgur.com/Qn6xkCZ.png');
position:absolute ;
background-size: contain;
width:100%;
z-index:0;
height:100%;
background-repeat: no-repeat;
}
您会注意到右侧有一个溢出。 (此时不能上传超过2个链接)
您也可以在我的网站http://jenngaudio.x10host.com/Flower%20Spark/查看它
我已经尝试过overflow-x: hidden 属性,但它会导致整个页面出现问题——可能是因为我使用的是响应式骨架。
【问题讨论】:
标签: jquery html css hover overflow