0
作爲我之前的問題here的後續,我試圖在頁面的兩側製作懸停圖像。圖像懸停運動會導致X軸溢出?
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
屬性,但它會導致問題的整個頁面 - 可能是因爲我用的是響應式骨架。
感謝又一次的幫助和扶正我錯了JS,我不是很熟悉,但我會記住這記住從現在起的句柄! – Jennga