그림 부상 실례

4697 단어

<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>title>
    <style>
        *{
            margin:0;
            height:0;
        }
        div{
            position: absolute;
        }
        img{
            width: 100px;
            height:100px;
        }
    style>
head>
<body>
  <div id="main"><img src="images/01.jpeg" alt=""/>div>
body>
<script type="text/javascript">
        //          div  
        var img = document.getElementById('main');
        var x = 10,y = 10;//          
        var xspeed = 1;//        
        var yspeed = 1;//        
        var w = document.documentElement.clientWidth - 100;//         
        var h = document.documentElement.clientHeight - 100;//         
        function float1() {
            if (x > w || x < 0) {
                xspeed = -xspeed;
            }
            if (y > h || y < 0) {
                yspeed = -yspeed;
            }
            x=x+xspeed;
            y=y+yspeed;
            img.style.left = x + "px";
            img.style.top = y + "px";

        }
        setInterval("float1()", 10);
script>
html>

좋은 웹페이지 즐겨찾기