这是我的Fiddle。
我正面临滚动问题。
我在Chrome中打开页面,滚动工作完全正常,当内容完成时停止。但是在firefox
中,即使内容已完成,它也会继续滚动,因为我已将固定宽度定义为div。
我的问题是我不知道会有多少图像,因为它将来自数据库,所以我不能使用固定宽度进行滚动。
我怎样才能解决这个问题。
我使用鼠标拖动滚动。
#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;
}
<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>
$(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) {}
}
});
我在这里做错了什么?
答案 0 :(得分:1)
将display: inline-flex; width:auto;
添加到.tl-events
,然后检查。
答案 1 :(得分:0)
似乎你必须得到包裹li
选项的元素的宽度来设置.tl-events的宽度。您不能使用像.tl-events { width: 11800px;
这样的静态宽度。你怎么解决。
var welcome = $('.welcome'), cont=0;
$(welcome).each(function(index) {
cont++;
});
var welcome_w = $('.welcome').width * cont;
$('#timeline').css('width', welcome_w);
你需要元素'welcome'来获取它的宽度并将它乘以欢迎元素的数量。在$(document).ready
功能中尝试此操作。并且重要会从.tl-events
课程的css中删除您的宽度。