這是我的Fiddle。跨瀏覽器水平圖像滾動問題
我在滾動中遇到問題。 我在Chrome中打開頁面時,滾動效果非常好,當內容完成時它會停止。但在firefox
中,即使內容已完成,它也會繼續滾動,因爲我已將固定寬度定義爲div。
我的問題是我不知道會有多少圖像,因爲它會來自數據庫,所以我不能使用固定的寬度進行滾動。
我怎樣才能得到這個固定的。
我使用鼠標拖動進行滾動。
這裏是我的CSS代碼
#timeline {
height: 375px;
margin-top: 10px;
padding: 20px;
overflow: auto;
}
.tl-events {
width: 11800px;
list-style: none;
padding: 0;
margin: 0;
}
.tl-events li {
float: left;
width: 300px;
margin-right: 10px;
}
.tl-events ul {
list-style: none;
margin: 0;
padding: 0;
}
這是我的HTML
<div id="timeline">
<ul class="tl-events">
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
<li class="welcome">
<h2>Welcome to the interactive timeline of Google history!</h2>
<p>Travel through time by dragging the timeline or the slider below. Click on any event to see more information.</p>
</li>
</ul>
</div>
這裏是我的JS
$(document).ready(function() {
$('#timeline').mousedown(function (event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('scrollLeft', this.scrollLeft);
return false;
}).mouseup(function (event) {
$(this).data('down', false);
}).mousemove(function (event) {
if ($(this).data('down') == true) {
this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
}
}).mousewheel(function (event, delta) {
this.scrollLeft -= (delta * 30);
}).css({
'overflow' : 'hidden',
'cursor' : '-moz-grab'
});
});
$(window).mouseout(function (event) {
if ($('#timeline').data('down')) {
try {
if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
$('#timeline').data('down', false);
}
} catch (e) {}
}
});
我到底錯在這裏做什麼?
對不起,我是新用戶。 –