当前位置: 首页 > 面试题库 >

非常简单,非常流畅的JavaScript字幕

范麒
2023-03-14
问题内容

我试图找到一个非常简单,流畅,轻巧的javascript或jquery字幕。我已经尝试过丝绸选框之类的东西,但不适用于我正在使用的应用程序。因此,越短越好,越好-并且越容易调试。有人知道字幕易于实现的JavaScript替换吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
var tWidth='300px';                  // width (in pixels)
var tHeight='25px';                  // height (in pixels)
var tcolour='#ffffcc';               // background colour:
var moStop=true;                     // pause on mouseover (true or false)
var fontfamily = 'arial,sans-serif'; // font for content
var tSpeed=3;                        // scroll speed (1 = slow, 5 = fast)

// enter your ticker content here (use \/ and \' in place of / and ' respectively)
var content='Are you looking for loads of useful information <a href="http:\/\/javascript.about.com\/">About Javascript<\/a>? Well now you\'ve found it.';

var cps=-tSpeed; var aw, mq; var fsz = parseInt(tHeight) - 4; function startticker(){if (document.getElementById) {var tick = '<div style="position:relative;width:'+tWidth+';height:'+tHeight+';overflow:hidden;background-color:'+tcolour+'"'; if (moStop) tick += ' onmouseover="cps=0" onmouseout="cps=-tSpeed"'; tick +='><div id="mq" style="position:absolute;right:0px;top:0px;font-family:'+fontfamily+';font-size:'+fsz+'px;white-space:nowrap;"><\/div><\/div>'; document.getElementById('ticker').innerHTML = tick; mq = document.getElementById("mq"); mq.style.right=(10+parseInt(tWidth))+"px"; mq.innerHTML='<span id="tx">'+content+'<\/span>'; aw = document.getElementById("tx").offsetWidth; lefttime=setInterval("scrollticker()",50);}} function scrollticker(){mq.style.right = (parseInt(mq.style.right)>(-10 - aw)) ?
mq.style.right = parseInt(mq.style.right)+cps+"px": parseInt(tWidth)+10+"px";} window.onload=startticker;
</script>
</head>
<body>
<div id="ticker">
    this is a simple scrolling text!
</div>
</body>
</html>

问题答案:

希望这对您有所帮助,加油!

html

<h1>Hello World!</h1>
<h2>I'll marquee twice</h2>
<h3>I go fast!</h3>
<h4>Left to right</h4>
<h5>I'll defer that question</h5>​

jQuery代码

 (function($) {
        $.fn.textWidth = function(){
             var calc = '<span style="display:none">' + $(this).text() + '</span>';
             $('body').append(calc);
             var width = $('body').find('span:last').width();
             $('body').find('span:last').remove();
            return width;
        };

        $.fn.marquee = function(args) {
            var that = $(this);
            var textWidth = that.textWidth(),
                offset = that.width(),
                width = offset,
                css = {
                    'text-indent' : that.css('text-indent'),
                    'overflow' : that.css('overflow'),
                    'white-space' : that.css('white-space')
                },
                marqueeCss = {
                    'text-indent' : width,
                    'overflow' : 'hidden',
                    'white-space' : 'nowrap'
                },
                args = $.extend(true, { count: -1, speed: 1e1, leftToRight: false }, args),
                i = 0,
                stop = textWidth*-1,
                dfd = $.Deferred();

            function go() {
                if(!that.length) return dfd.reject();
                if(width == stop) {
                    i++;
                    if(i == args.count) {
                        that.css(css);
                        return dfd.resolve();
                    }
                    if(args.leftToRight) {
                        width = textWidth*-1;
                    } else {
                        width = offset;
                    }
                }
                that.css('text-indent', width + 'px');
                if(args.leftToRight) {
                    width++;
                } else {
                    width--;
                }
                setTimeout(go, args.speed);
            };
            if(args.leftToRight) {
                width = textWidth*-1;
                width++;
                stop = offset;
            } else {
                width--;            
            }
            that.css(marqueeCss);
            go();
            return dfd.promise();
        };
    })(jQuery);

$('h1').marquee();
$('h2').marquee({ count: 2 });
$('h3').marquee({ speed: 5 });
$('h4').marquee({ leftToRight: true });
$('h5').marquee({ count: 1, speed: 2 }).done(function() { $('h5').css('color', '#f00'); })​


 类似资料:
  • 我搜索了数据库和食谱,但似乎找不到正确的答案。我有一个非常简单的python代码,它总结了一个范围内的自我权力。我需要这个非常非常大的数字的最后十位,我已经尝试了get上下文(). prec,但是我仍然达到了极限。 代码如下: 我怎么能看到这些美丽的数字?它在我的四核上打印速度相对较快。这只是为了给ProjectEuler带来乐趣,问题#48,请不要破坏者。我不想要解决方案,也不想让工作为我完成,

  • 本文向大家介绍非常简单的Shell菜单脚本,包括了非常简单的Shell菜单脚本的使用技巧和注意事项,需要的朋友参考一下 本文给大家分享一个自己简单编写的Shell菜单脚本,傻瓜式的人机交互,人人都可以操作linux。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

  • 问题内容: 简单的问题,但我花了一个多小时。我的代码如下。我需要使SomeClass sc动态化。因此,您将类名作为字符串传递给函数,然后使用该类代替静态someClass。怎么做呢? 我想要的是 编辑:上面是简化。实际的代码是这个 另一个简单的改写:我使用request.getRequest()得到一个对象。我不知道那个物体是什么。因此,我需要将其强制转换为提供的类字符串名称。怎么做?就这样。–

  • 这些方法如下所示: 编辑 我尝试使用、和。 我曾尝试直接在上调用,但它也没有捕捉到这一点。

  • 本文向大家介绍JavaScript实现非常简单实用的下拉菜单效果,包括了JavaScript实现非常简单实用的下拉菜单效果的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了JavaScript实现非常简单实用的下拉菜单效果。分享给大家供大家参考。具体如下: 这是一款实用的JS下拉菜单,鼠标移上菜单就显示出二级菜单,是从其它网站上整理下来的,修改花了不少时间,现在去除了一些无用代码,更简洁了,

  • 主要内容:非常简单的英语自我介绍【篇1】,非常简单的英语自我介绍【篇2】,非常简单的英语自我介绍【篇3】,非常简单的英语自我介绍【篇4】,非常简单的英语自我介绍【篇5】,非常简单的英语自我介绍【篇6】,非常简单的英语自我介绍【篇7】,非常简单的英语自我介绍7篇 非常简单的英语自我介绍?有很多人以为自我介绍很难写?其实是没有抓住精髓,把简单的问题给复杂化了。那么下面小编给大家带来了非常简单的英语自我介绍,供大家参考。 非常简单的英语自我介绍【篇1】 My surname is Li wen, lo