Home  >  Article  >  Web Front-end  >  How to achieve the flashing effect of web page title

How to achieve the flashing effect of web page title

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-04-21 09:43:452885browse

This article will give you a detailed introduction to the method of achieving the flashing effect of web page titles. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to achieve the flashing effect of web page title

Code

// 获取当前网页标题
    // console.log(document.title);
    // document.title = '快点 打开'

    // 如果状态的数量是固定的一定要想到两个固定的东西
    // 1. 取余
    // 2. switch……case……

    // 1.定时器
    // 2.两个标题
    // 这里空格必须使用全角的空格 否则不会在标题中显示
    var title1 = '[   ]标题名';
    var title2 = '[新提醒]标题名';
    var i = 0;
    setInterval(function() {
        // 切换两个标题的显示
        // 判断
        if (i % 2 == 0) {
            document.title = title1;
        } else {
            document.title = title2;
        }
        i++;
    }, 500);

It should be noted that

  • cannot ignore the definition of i variable

  • You cannot use half-width spaces for spaces

[Recommended learning: javascript advanced tutorial

The above is the detailed content of How to achieve the flashing effect of web page title. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete