- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我做了DEMO请参阅显示所有评论及其时间的表格。
当视频开始播放时,随着视频播放时间的推移,它开始显示每条评论。
我面临的问题是它不会跳转到表格中的正确行(表格看起来像文本区域)
它来回走动,但不会瞄准。
我希望每次弹出评论时,正确的行都显示在表格的顶部位置。
它应该滚动,并跟随表中当前评论的行。
我该如何解决这个问题?任何人都可以修改和更新我的 jsfiddle 吗?
Javascript
var row= '';
jQuery(document).ready(function () {
var fixedTime = 0;
$('#video').on('timeupdate',function(e){
if(this.currentTime.toFixed() != fixedTime){
showComments(fixedTime);
fixedTime = this.currentTime.toFixed()
}
});
});
var comments = [
{'time':'10','message':'hello! 10 secs has past'},
{'time':'11','message':'hello! 11 secs has past'},
{'time':'10','message':'hello! 10-2 secs has past'},
{'time':'5','message':'hello! 5 secs has past'},
{'time':'20','message':'hello! 20 secs has past'},
{'time':'21','message':'hello! 21 secs has past'},
{'time':'20','message':'hello! 20-2 secs has past'},
{'time':'25','message':'hello! 25 secs has past'},
{'time':'30','message':'hello! 30 secs has past'}
];
function showComments(time){
var coms = findComments(time);
if(coms[0]){
$('.newsticker p').animate({"marginLeft":"400px","opacity":".0"}, 600).fadeOut(100);
$('.newsticker').append("<p style='margin-left:400px;opacity:0'>"+coms[0].message+"</p>");
$('.newsticker p').animate({"marginLeft":"0px","opacity":"1"}, 600);
var row = "tr.comment" + time;
$("tr").css("background-color","#ffffff");
jQuery(row).each(function() {
$(this).css("background","#87cefa");
$('div#container').animate({
scrollTop: jQuery(this).offset().top
}, 500);
});
}
}
function findComments(time){
return $.grep(comments, function(item){
return item.time == time;
});
}
HTML
<body>
<div class="newsticker">
</div>
<br />
<br />
<video id="video" width="320" height="180" controls="controls" autoplay="autoplay" name="media"><source src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4"></video>
</body>
<div id="container" style="border:solid 1px;height:70px; width:500px; overflow-y:scroll;">
<table border="0" height="100" width="400">
<tr class="comment5">
<td>00:00:05</td>
<td>hello! 5 secs has past</td>
</tr>
<tr class="comment10">
<td>00:00:10</td>
<td>hello! 10 secs has past</td>
</tr>
<tr class="comment10">
<td>00:00:10</td>
<td>hello! 10-2 secs has past</td>
</tr>
<tr class="comment11">
<td>00:00:11</td>
<td>hello! 11 secs has past</td>
</tr>
<tr class="comment20">
<td>00:00:20</td>
<td>hello! 20 secs has past</td>
</tr>
<tr class="comment20">
<td>00:00:20</td>
<td>hello! 20-2 secs has past</td>
</tr>
<tr class="comment21">
<td>00:00:21</td>
<td>hello! 21 secs has past</td>
</tr>
<tr class="comment25">
<td>00:00:25</td>
<td>hello! 25 secs has past</td>
</tr>
<tr class="comment30">
<td>00:00:30</td>
<td>hello! 30 secs has past</td>
</tr>
</table>
</div>
CSS
div.newsticker{
border:1px solid #666666;
width:100%;
height:50px;
}
.newsticker p{
float:left;
position:absolute;
}
最佳答案
我不知道为什么,但是 offset().top
为注释行提供的值太大了,没有用...它们只是让div一直向下滚动。
我用 DOM 属性 offsetTop
替换它,它似乎工作正常:
$('div#container').animate({
scrollTop: this.offsetTop
}, 500);
关于javascript - 为什么这不会跳到正确的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18406505/
如果我有一个使用 strpos() 导出的字符串位置,我将如何跳到该位置?我正在使用一个需要从该位置或下一行开始处开始的函数。 我该怎么做?速度是一个因素。 最佳答案 您可以使用 跳到字符串中的任何字
我构建了一个表单,用数组中的数据填充字段。 我有 2 个按钮,一个将使用 Ajax“发布”- 提交,另一个我试图跳到数组中的下一个对象 - 跳过。 我不知道如何让跳过按钮起作用。我有 found允许您
我实现了一个具有开始和结束状态的 CSS3 动画。一旦达到结束状态,动画就会停止并且不再重复。我需要做的是有一个绕过整个动画但显示最终状态的“跳到结束”链接。是否可以通过 CSS3 执行此操作。 这是
我有一个应用程序,我试图从 jQuery .animate 切换到 CSS3 转换,以响应滑动手势和按钮按下来左右移动卡片列表。 除了一件事,它现在运行良好。我希望该应用程序每次滑动一次移动一页卡片,
我下载了 Matchit 插件并将其用于我的 HTML 文件。一切都按预期工作,直到我在我的列表中使用它。 reddit vim w3schools 如果光标在第一个 o
我下载了 Matchit 插件并将其用于我的 HTML 文件。一切都按预期工作,直到我在我的列表中使用它。 reddit vim w3schools 如果光标在第一个 o
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
在我的 Scala 代码中的 for 循环中,如果特定条件为真,我想跳到循环的开头并且不执行以下语句。在 Java 中,我可以使用“继续”来执行此操作。但是“继续”在 Scala 中似乎不起作用。那么
我犯了一个错误,将 Visual Studio 项目从 2008 年升级到 2010 年,但没有先检查我以前的更改。因此,我有一个巨大的系统生成文件(10k+ 行),每 4 行更改一次。 我通常很擅长
#include #include int main() { char nameuser[12]; int userChoice; printf("Name(Max. 12 Chara
我正在使用 Firebase 存储上传文件。 https://firebase.google.com/docs/storage/web/upload-files#monitor_upload_prog
我有一个带有 TransitionListener 的 MotionLayout,我的 MotionScene 的进度似乎从 0 到 1:
大家好,我对 qprogressbar 有疑问。我怎样才能使它光滑?我希望它从 0 到 100% 顺利进行。我将它与 reply 变量一起使用,该变量从 php 脚本读取数据并返回给我数据。我需要等待
我有一个非常非常奇怪的问题,我无法弄清楚。所以你可以看看,这是我的代码; point * findLongPaths(point * points, double threshold_distance
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在播放一个电视节目,该节目已使用 AVQueuePlayer 在我的项目中分成不同的章节。我还想提供在 AVQueuePlayer 已经播放时跳到上一章/下一章或即时选择不同章节的可能性。 AVQ
我想在我的环境中设置这样的东西。 [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKe
这个问题已经有答案了: Identity increment is jumping in SQL Server database (6 个回答) 已关闭 8 年前。 我遇到了一个奇怪的情况,其中 SQ
当我进入循环时,我的“计数器”从 1 跳到 4。有任何想法吗?代码和输出如下: static bool harvestLog() { ifstream myFile("LOGS/ex0
我正在尝试解决所有关于 codility 的类(class),但我未能解决以下问题:Ladder by codility 我在整个互联网上进行了搜索,但没有找到令我满意的答案,因为没有人回答为什么最大
我是一名优秀的程序员,十分优秀!