Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

UNIT

연구대상 스크립트 1 본문

카테고리 없음

연구대상 스크립트 1

Hepheir 2016. 5. 7. 03:16

<!-- 와우 -->

<script>

let buttons = [];

let form = $("#form")

const stride = 5;


const random = function(arr){

 return arr[Math.floor(Math.random()*arr.length)]

}


for (let i = 0; i < 10; i++) {

 buttons.push({

   button: $("#button" + i),

   xDir: random(["left", "right"]),

   yDir: random(["up", "down"]),

   xVel: random([1, 2, 3]),

   yVel: random([1, 2, 3])

 })

}


setInterval( () => {

 let xBoundary = form.width() - buttons[0].button.width()

 let yBoundary = form.height() - buttons[0].button.height()

 for (let i = 0; i < buttons.length; i++) {

   buttons[i].button.css({

     left: (index, oldValue) => {

       if(buttons[i].xDir === "left") {

         if(parseInt(oldValue) < xBoundary) {

           return parseInt(oldValue) + buttons[i].xVel

         } else {

           buttons[i].xDir = "right";

           return parseInt(oldValue)

         }

       } else if(buttons[i].xDir === "right") {

         if(parseInt(oldValue) > 0) {

           return parseInt(oldValue) - buttons[i].xVel;

         } else {

           buttons[i].xDir = "left";

           return parseInt(oldValue)

         }

       }

     },

     top: (index, oldValue) => {

        if(buttons[i].yDir === "down") {

         if(parseInt(oldValue) < yBoundary) {

           return parseInt(oldValue) + buttons[i].yVel

         } else {

           buttons[i].yDir = "up";

           return parseInt(oldValue)

         }

       } else if(buttons[i].yDir === "up") {

         if(parseInt(oldValue) > 0) {

           return parseInt(oldValue) - buttons[i].yVel;

         } else {

           buttons[i].yDir = "down";

           return parseInt(oldValue)

         }

       }

     }

   })

 }

}, 20)


let count = 0;

$(".button").mousedown( function() {

 if(count < 10) {

   if (count === 0) {

     $(".number").append("(" +this.innerHTML)

   } else if (count === 2) {

     $(".number").append(this.innerHTML + ")")

   } else if (count === 5) {

     $(".number").append(this.innerHTML + "-")

   } else {

     $(".number").append(this.innerHTML)

   }

   count++;

 }

})


$(".startOver").click( () => {

 $(".number").html("");

 count = 0;

})


$(".enter").click ( () => {

 alert("You've submitted " + $(".number").html())

})

</script>















https://www.facebook.com/BoriJam/posts/698714003604754

Comments