8-1 模拟live messenger的振动闪屏.htm

来自「JAVASCRIPT完全自学手册,中源码的验证修订实例」· HTM 代码 · 共 52 行

HTM
52
字号
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>8-1  模拟Live Messenger的振动闪屏</title>
<!-- 样式表 -->
<style>
* { font-size:12px; font-family:宋体, Arial; font-weight:normal; color:#333; } /*规定了所有的字体样式*/
textarea { width:100%; height:98%; border:1px solid black; } /*定义多行文本框的样式*/
</style>
<!-- 脚本部分 -->
<script>
function resizeWindow(){
    var windowWidth = 240, windowHeight = 180;
    window.moveTo((screen.availWidth - windowWidth)/2,(screen.availHeight-windowHeight)/2);
    window.resizeTo(windowWidth, windowHeight);
}

function shakeWin(stepId){
    var stepId;
    if(!stepId)stepId = 0;
    switch(stepId){
        case 0:
            window.moveBy(-5,-5);
        break;
        case 1:
            window.moveBy(10,0);
        break;
        case 2:
            window.moveBy(-10,10);
        break;
        case 3:
            window.moveBy(10,0);
        break;
        case 4:
            window.moveBy(-5,-5);
        break;
        default:
            return;
    }
    stepId++;
    setTimeout("shakeWin(" + stepId + ");", 20);
}

function $(str){ return(document.getElementById(str)); }

window.onload = resizeWindow;
</script>
</head>
<body style="overflow:auto;">
<input type="button" value="点击查看振动闪屏效果" onclick="shakeWin();" />
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?