HTML字幕替代方案

HTML字幕替代方案,html,marquee,Html,Marquee,这里绝对是初学者。从字面上说,上个星期刚开始搞乱HTML 我试图想出一种可以在网站上进行html编码的字幕效果。我们有一个基本的HTML字幕设置,但它是跳跃和难以阅读。我不知道该怎么做。您可以使用jQuery来归档marquee的结果 看这里: 在这里: 如前所述:永远不要使用字幕 google search for marquee jquery列出了许多结果您可以使用jquery来归档marquee的结果 看这里: 在这里: 如前所述:永远不要使用字幕 google search for ma

这里绝对是初学者。从字面上说,上个星期刚开始搞乱HTML


我试图想出一种可以在网站上进行html编码的字幕效果。我们有一个基本的HTML字幕设置,但它是跳跃和难以阅读。我不知道该怎么做。

您可以使用jQuery来归档marquee的结果

看这里: 在这里:

如前所述:永远不要使用字幕


google search for marquee jquery列出了许多结果

您可以使用jquery来归档marquee的结果

看这里: 在这里:

如前所述:永远不要使用字幕


google search for marquee jquery列出了很多结果

除了marquee,没有简单的选择。如果你想找到一个标准的解决方案,你必须是一个专业的javascript程序员,而不是一个简单的html标签,你必须去很多行代码

除了Google Chrome之外,大多数标准Web浏览器都支持它,但它无法按照marquee的标准进行渲染

对于Chrome和Chrome,您只需要使用以下javascript代码。。。你不需要在IE、Edge、Mozilla、Opera等中使用它

var oMarquees = [], oMrunning,
        oMInterv =        20,     //interval between increments
        oMStep =          1,      //number of pixels to move between increments
        oStopMAfter =     0,     //how many seconds should marquees run (0 for no limit)
        oResetMWhenStop = false,  //set to true to allow linewrapping when stopping
        oMDirection =     'right'; //'left' for LTR text, 'right' for RTL text

/***     Do not edit anything after here     ***/
function doMStop() {
        clearInterval(oMrunning);
        for( var i = 0; i < oMarquees.length; i++ ) {
                oDiv = oMarquees[i];
                if( oResetMWhenStop ) {
                        oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
                        oDiv.mchild.style.whiteSpace = '';
                        oDiv.style.height = '';
                        oDiv.style.overflow = '';
                        oDiv.style.position = '';
                        oDiv.mchild.style.position = '';
                        oDiv.mchild.style.top = '';
                }
        }
        oMarquees = [];
}
function doDMarquee() {
        if( oMarquees.length || !document.getElementsByTagName ) { return; }
        var oDivs = document.getElementsByTagName('div');
        for( var i = 0, oDiv; i < oDivs.length; i++ ) {
                oDiv = oDivs[i];
                if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
                        if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
                        if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
                        oDiv.mchild.style.cssText += ';white-space:nowrap;';
                        oDiv.mchild.style.whiteSpace = 'nowrap';
                        oDiv.style.height = oDiv.offsetHeight + 'px';
                        oDiv.style.overflow = 'hidden';
                        oDiv.style.position = 'relative';
                        oDiv.mchild.style.position = 'absolute';
                        oDiv.mchild.style.top = '0px';
                        oDiv.mchild.style[oMDirection] = (oDiv.mchild.style[oMDirection] == '')?(oDiv.offsetWidth + 'px'):oDiv.mchild.style[oMDirection];
                        oMarquees[oMarquees.length] = oDiv;
                        i += 2;
                }
        }
        oMrunning = setInterval('aniMarquee()',oMInterv);
        if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
        var oDiv, oPos;
        for( var i = 0; i < oMarquees.length; i++ ) {
                oDiv = oMarquees[i].mchild;
                oPos = parseInt(oDiv.style[oMDirection]);
                if( oPos <= -1 * oDiv.offsetWidth ) {
                        oDiv.style[oMDirection] = oMarquees[i].offsetWidth + 'px';
                } else {
                        oDiv.style[oMDirection] = ( oPos - oMStep ) + 'px';
                }
        }
}
if( window.addEventListener ) {
        window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
        document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
        window.attachEvent('onload',doDMarquee);
}

没有简单的替代品可以替代字幕。如果你想找到一个标准的解决方案,你必须是一个专业的javascript程序员,而不是一个简单的html标签,你必须去很多行代码

除了Google Chrome之外,大多数标准Web浏览器都支持它,但它无法按照marquee的标准进行渲染

对于Chrome和Chrome,您只需要使用以下javascript代码。。。你不需要在IE、Edge、Mozilla、Opera等中使用它

var oMarquees = [], oMrunning,
        oMInterv =        20,     //interval between increments
        oMStep =          1,      //number of pixels to move between increments
        oStopMAfter =     0,     //how many seconds should marquees run (0 for no limit)
        oResetMWhenStop = false,  //set to true to allow linewrapping when stopping
        oMDirection =     'right'; //'left' for LTR text, 'right' for RTL text

/***     Do not edit anything after here     ***/
function doMStop() {
        clearInterval(oMrunning);
        for( var i = 0; i < oMarquees.length; i++ ) {
                oDiv = oMarquees[i];
                if( oResetMWhenStop ) {
                        oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
                        oDiv.mchild.style.whiteSpace = '';
                        oDiv.style.height = '';
                        oDiv.style.overflow = '';
                        oDiv.style.position = '';
                        oDiv.mchild.style.position = '';
                        oDiv.mchild.style.top = '';
                }
        }
        oMarquees = [];
}
function doDMarquee() {
        if( oMarquees.length || !document.getElementsByTagName ) { return; }
        var oDivs = document.getElementsByTagName('div');
        for( var i = 0, oDiv; i < oDivs.length; i++ ) {
                oDiv = oDivs[i];
                if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
                        if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
                        if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
                        oDiv.mchild.style.cssText += ';white-space:nowrap;';
                        oDiv.mchild.style.whiteSpace = 'nowrap';
                        oDiv.style.height = oDiv.offsetHeight + 'px';
                        oDiv.style.overflow = 'hidden';
                        oDiv.style.position = 'relative';
                        oDiv.mchild.style.position = 'absolute';
                        oDiv.mchild.style.top = '0px';
                        oDiv.mchild.style[oMDirection] = (oDiv.mchild.style[oMDirection] == '')?(oDiv.offsetWidth + 'px'):oDiv.mchild.style[oMDirection];
                        oMarquees[oMarquees.length] = oDiv;
                        i += 2;
                }
        }
        oMrunning = setInterval('aniMarquee()',oMInterv);
        if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
        var oDiv, oPos;
        for( var i = 0; i < oMarquees.length; i++ ) {
                oDiv = oMarquees[i].mchild;
                oPos = parseInt(oDiv.style[oMDirection]);
                if( oPos <= -1 * oDiv.offsetWidth ) {
                        oDiv.style[oMDirection] = oMarquees[i].offsetWidth + 'px';
                } else {
                        oDiv.style[oMDirection] = ( oPos - oMStep ) + 'px';
                }
        }
}
if( window.addEventListener ) {
        window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
        document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
        window.attachEvent('onload',doDMarquee);
}

我的建议是改用旋转木马。用户可以对其进行更多的控制,因为只需单击鼠标即可停止和启动旋转木马


此处的材料设计旋转木马:

我的建议是使用旋转木马。用户可以对其进行更多的控制,因为只需单击鼠标即可停止和启动旋转木马


此处的材质设计旋转木马:

永远不要使用字幕。你的用户会因此讨厌你。这是有原因的:CSS转换和动画是一种更合适的机制。@Patrickhoffman我所看到的几乎每一个新闻频道都使用一个类似于字幕的ticker来显示他们现在没有谈论的新闻。marquee有一些有效的用途,但因为它很酷,所以肯定不是其中之一:@NiettheDarkAbsol:好的。但我仍然讨厌它们。@Patrickhoffman Fair够了XD我个人讨厌旋转木马,但很多人滥用它们……永远不要使用字幕。你的用户会因此讨厌你。这是有原因的:CSS转换和动画是一种更合适的机制。@Patrickhoffman我所看到的几乎每一个新闻频道都使用一个类似于字幕的ticker来显示他们现在没有谈论的新闻。marquee有一些有效的用途,但因为它很酷,所以肯定不是其中之一:@NiettheDarkAbsol:好的。但我仍然讨厌它们。@Patrickhoffman Fair够了XD我个人讨厌旋转木马,但很多人滥用它们……就目前而言,这是一个只有链接的答案。我真的很抱歉再次询问,但是我不太明白jQuery是什么/我是如何将它合并到我的HTML编码中的jQuery是一个JavaScript框架,它可以让你很容易地在你的站点中添加JavaScript。您可以添加jQuery库和要在html标题部分中使用的jQuery主库,并像上面我的第二个链接中提到的那样使用它;就目前而言,这是一个只有链接的答案。我真的很抱歉再问一次,但我不太明白jQuery是什么/我是如何将它整合到我的HTML编码中的。jQuery是一个JavaScript框架,它可以让你很容易地在你的网站中添加JavaScript。您可以添加jQuery库和要在html标题部分中使用的jQuery主库,并像上面我的第二个链接中提到的那样使用它;您可以使用CSS创建类似的效果。更大的问题是,你为什么要这样做?你可以用CSS创建类似的效果。更大的问题是,你为什么要这么做?