我想在jQuery中的鼠標移動上實現滾動。在jQuery中實現鼠標移動的滾動
滾動的目的是查看完整的圖像..它已出現莫代爾彈出窗口。
此圖像是Div的背景圖片。
我能夠使用jQuery在鼠標移動上上下移動圖像。 但問題是在完成圖像滾動後,div的背景會繼續滾動事件。 我必須阻止這種情況發生。
參考ü可以看到: -
http://zovi.com/california-dream-t-shirt-white--S123RNM84602#2
點擊大圖上,一個模式彈出出現。在滾動時,完整的圖像在沒有額外滾動的情況下被查看。
我正試圖做到這一點。 在此先感謝..
這裏是我的代碼: -
完整的HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
.backdrop
{
position: relative;
height: 300px; /*could be anything really..*/
width: 400px; /*could be anything really..*/
border: 3px solid #6699ff;
background: url('image/TShirt/tshirtpicZoom1.jpg') 0 0 no-repeat;
}
.direction
{
position: absolute;
width: 50%;
height: 100%;
}
.top
{
left: 0;
top: 0;
width:100%;
}
.bottom
{
left: 0;
top: 50%;
width:100%;
}
</style>
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script>
$(function() {
var x = 0,
y = 0,
rate = 0,
maxspeed = 10;
var backdrop = $('.backdrop');
$('.direction', backdrop).mousemove(function (e) {
var $this = $(this);
var top = $this.is('.top');
if (top) {
var h = $this.height();
rate = (h - e.pageY - $(this).offset().top + 1)/h;
}
else {
var h = $this.height();
rate = -(e.pageY - $(this).offset().top + 1)/h;
}
});
backdrop.hover(
function() {
var scroller = setInterval(moveBackdrop, 10);
$(this).data('scroller', scroller);
},
function() {
var scroller = $(this).data('scroller');
clearInterval(scroller);
}
);
function moveBackdrop() {
y += maxspeed * rate;
var newpos = x + 'px ' + y + 'px';
backdrop.css('background-position', newpos);
}
});
</script>
</head>
<body>
<div class="backdrop">
<div class="direction top">
</div>
<div class="direction bottom">
</div>
</div>
</body>
</html>