如何检查字幕是否滚动 [英] How to check if marquee is scrolling
本文介绍了如何检查字幕是否滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jQuery检测字幕是否滚动?
How to detect if marquee is scrolling on button click using jQuery?
<marquee>Scrolling text here, moving constantly</marquee>
<button id="btnCheck">Button</button>
我的jQuery代码如下:
My jQuery code looks like:
$(function (){
var marquee = $("marquee")[0];
$("#btnCheck").click(function (){
// How to check if marquee is scrolling here
});
});
推荐答案
您可以在 marquee
内添加 p
并检查其 left
位置.如果已更改,则您的 marquee
会滚动,否则,不会滚动,就像以下代码段一样:
You can add a p
inside the marquee
and check its left
position. If it is changed, then your marquee
is scrolling, otherwise, it is not, like this snippet:
$(function() {
$("#btnCheck").click(function() {
var initialLeft = $('marquee > p').position().left;
setTimeout(function() {
var currentLeft = $('marquee > p').position().left;
if (initialLeft !== currentLeft) {
alert("Marquee is scrolling!");
}else{
alert("Marquee is not scrolling");
}
}, 100);
});
});
p {
margin: 0
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<marquee loop="1"><p>Scrolling text here, moving constantly</p></marquee>
<button id="btnCheck">Button</button>
P/s:
此(HTML
< marquee>
)功能已过时.尽管在某些浏览器中仍然可以使用,不建议使用它,因为可以随时将其删除.尝试避免使用它.
This (The HTML
<marquee>
) feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
这篇关于如何检查字幕是否滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文