gpt4 book ai didi

javascript - 我在 div 中有一个长表,当我滚动表时,我想看到它惯性移动 HTML

转载 作者:行者123 更新时间:2023-11-28 06:15:02 25 4
gpt4 key购买 nike

我有一个长表(宽度很大),当我从左向右滚动该表时,我希望它惯性移动。我的当前版本只是当我用手指滚动它时,它会移动但是当我举起手指时它会停止。我应该怎么办?这是我在 div 中为该表编写的 HTML 代码的一部分。

           <div class="welcomeProgram">
<p class=programTitle>Project</p>
<div class="outer">
<div class="inner">
<table>
<tr>
<td><a href="#"><img src="img/ast_youxue.png"/></a><p>Project1</p></td>
<td><a href="#"><img src="img/canada_youxue2.png"/></a><p>project2</p></td>
<td><a href="#"><img src="img/usa_youxue2.png"/></a><p>project3</p></td>
<td><a href="#"><img src="img/uk_youxue2.png"/></a><p>project4</p></td>
</tr>
</table>
</div>
</div>
</div>

还有我的CSS代码:

table {
table-layout: fixed;
width: 100%;
*margin-left: -100px;/*ie7*/
}
td, th {
vertical-align: top;
padding:2px;
width:330px;
}

.outer {
position:relative;
margin-top: 2%;
}
.inner {
overflow-x:scroll;
overflow-y:visible;
width:97%;
margin-left:0%;
-webkit-overflow-scrolling: touch;
}
.inner img{
width: 100%;
}
.inner p{
font-size: 20px;
margin-top: 4%;
margin-left: 1%;
}

最佳答案

我不确定你在问什么。 “惯性”不是字典里的一个词。惯性是,但它没有运动,也就是保持静止的 body 。请参阅:http://www.dictionary.com/browse/inertia

听起来好像表格已经在做它需要做的事情,当用户的光标或手指松开表格时……它停止了。

如果您想让它继续移动,您需要使用像 jQuery 这样的库来为它制作动画。 HTML + CSS 自己不会这样做。您可以开始滚动 onKeyDown & 然后 onMouseMove。它类似于使用 jQuery 编写拖放操作。一旦你设置了 2 个标志来跟踪 onKeyDown 和 onMouseMove,其中两个标志都设置为 true,那么你可以使用 onKeyUp 事件来运行动画。您可以使用 .scrollLeft() 让它继续移动。请参阅:https://api.jquery.com/scrollleft/

能否请您澄清一下,您要找这张 table 做什么?

编辑:我试图将其添加到评论中,但它不适合它。看看这是否有帮助...

<html>
<head>
<style>
.wrap {
overflow-y: scroll;
}
table {
width: 10000px;
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
<footer>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script>
$(function() {
// Generate Table
var table = '<table border="1"><tr>';
for (var i=0; i<1000; i++) {
table += '<td>Hi</td>';
}
table += '</tr></table>';
$('.wrap').html(table);

// Run Animation
$('.wrap').on('scroll', function(){
$(this).animate({
scrollLeft: "+=50"
}, 800);
});
});
</script>
</footer>
</html>

关于javascript - 我在 div 中有一个长表,当我滚动表时,我想看到它惯性移动 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35945474/

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