跑马灯效果

<!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">
<head>
    <title>当你孤单你会想起谁!</title>
    <script type="text/javascript">
        var flag;
        function f1(obj) {
            flag = obj;
        }
        setInterval(function () {
            var title = document.title;//获取标题
            if (flag == "R") {
                //向右走
                var first = title.substr(title.length - 1);
                var last = title.substr(0, title.length - 1);
                document.title = first + last;
            }
            else {
                //向左走
                var first = title.substr(0, 1);
                var last = title.substr(1);
                document.title = last + first;
            };
        }, 800)
    </script>
</head>
<body>
    <input type="button" value="向左" id="btnLeft" onclick="f1('L')"/> &nbsp;&nbsp;
    <input type="button" value="向右" id="btnRight" onclick="f1('R')"/>
</body>
</html>

 

posted @ 2013-03-15 12:33  海藻  阅读(141)  评论(0编辑  收藏  举报