js---基础案例-点击按钮放大缩小盒子

效果图
js---基础案例-点击按钮放大缩小盒子_第1张图片js---基础案例-点击按钮放大缩小盒子_第2张图片

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        div{
            width: 100px;
            height: 100px;
            background: #ff0000;
            position: absolute;
            top: 300px;
            left: 300px;

        }
    </style>
    <title>Title</title>
</head>
<body>
<button id="bn+da"></button>
<button id="bn-xiao"></button>

<div id="d1"></div>
</body>
</html>
<script>
    var div=document.getElementById("d1");
    var bn1=document.getElementById("bn+da");
    var bn2=document.getElementById("bn-xiao");

    var a={
        kuan:100,
        gao:100,
        lefts:300,
        tops:300

    }

    bn1.onclick=function () {
        a.kuan+=10;
        div.style.width=a.kuan+"px";
        a.gao+=10;
        div.style.height=a.gao+"px";
        a.lefts-=5;
        div.style.left=a.lefts+"px";
        a.tops-=5;
        div.style.top=a.tops+"px";
    }

    bn2.onclick=function () {
        a.kuan-=10;
        div.style.width=a.kuan+"px";
        a.lefts+=5;
        div.style.left=a.lefts+"px";
        a.tops+=5;
        div.style.top=a.tops+"px";
        a.gao-=10;
        div.style.height=a.gao+"px";}


</script>

你可能感兴趣的:(JS基础练习题)