gpt4 book ai didi

jquery - 水平图像滚动的跨浏览器问题

转载 作者:行者123 更新时间:2023-11-28 17:59:54 24 4
gpt4 key购买 nike

这是我的 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) {}
}
});

我做错了什么?

最佳答案

添加display: inline-flex; width:auto;.tl-events 然后检查。

关于jquery - 水平图像滚动的跨浏览器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20661585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com