代码之家  ›  专栏  ›  技术社区  ›  sadmicrowave

jQuery在html页面标题标记中滚动字幕

  •  2
  • sadmicrowave  · 技术社区  · 16 年前

    我想使用jquery在我的html标题标记中放置一个滚动框,但不知道如何使用,似乎在任何地方都找不到一个好的解释。有人能帮我吗?

    3 回复  |  直到 16 年前
        1
  •  11
  •   Tatu Ulmanen    16 年前

    如果你只是想让它像 marquee 标签:

    (function titleMarquee() {
        document.title = document.title.substring(1)+document.title.substring(0,1);
        setTimeout(titleMarquee, 200);
    })();
    

    这是很基本的,但应该给你一个想法,如何调整到你喜欢的。

        2
  •  5
  •   sedran    13 年前

    在塔图·乌尔曼的回答中,空间字符有一个问题。如诗篇评论所述,在第一卷书后,所有空格都被删除。

    <title>Scrolling Title With Spaces</title>
    <title>crolling Title With SpacesS</title>
    <title>rolling Title With SpacesSc</title>
    <title>olling Title With SpacesScr</title>
    ...
    <title>Title With SpacesScrolling</title>
    

    正如你在上面看到的,我们失去了文字之间的空隙 Scrolling 和 Spaces document.title 在我们的javascript代码中的某个地方,在它的末尾加上一个空格或其他东西。然后,我们可以滚动 文档.标题 在另一个变量中滚动文本。这是塔图乌尔曼的修改代码。

    var documentTitle = document.title + " - ";
    
    (function titleMarquee() {
        document.title = documentTitle = documentTitle.substring(1) + documentTitle.substring(0,1);
        setTimeout(titleMarquee, 200);
    })();
    
        3
  •  0
  •   Amar Kholambe    11 年前

    在页眉上添加以下脚本,然后在body onload上调用scrlsts()函数

    <script type="text/javascript">
    var scrl = $('title').text();
    function scrlsts() {
         scrl = scrl.substring(1, scrl.length) + scrl.substring(0, 1);
         document.title = scrl;
         setTimeout("scrlsts()", 500);
         }
    <script>
    

        4
  •  0
  •   Samuel Liew cicero lopes    6 年前

    没有jQuery:

    setInterval(function () {
      $("head title").html($("head title").html().substring(1) + $("head title").html().substring(0,1));
    }, 300);
    
    推荐文章