메인메뉴 바로가기

HOME으로 가기


사용자함수 삼각함수를 이용한 원운동 이동모션 만들기

페이지 정보

profile_image
작성자 너갱이
댓글 0건 조회 6,681회 작성일 15-01-26 15:45

본문

-------------------- CSS ---------------------

 

#wrapper { width:100%; height:100%; }

#box { 

position:relative; 

margin:10% auto 0 auto; 

 

width:400px; 

height:400px; 

border:1px solid #ccc;

border-radius: 50%;

        cursor: pointer; 

}

#ball {

position:absolute; 

left:50%;

top:50%;

margin: -20px 0 0 -20px;

}

 

 

 

---------------- JS --------------

var Ball = {

interval : null,

t : 0,

init : function(){

Ball.obj = $("#ball");

//$("#ball").css({"top":0});

Ball.start();

 

$("#box").click(function(){

if(Ball.interval) Ball.stop();

else Ball.start();

});

},

start : function(){

Ball.interval = setInterval(function(){

$("#ball").css({

"left": ( Math.sin(Ball.t) *50  )+50+"%", 

"top": ( Math.cos(Ball.t) *50  )+50+"%",

//스케일

//"width" : ( Math.cos(Ball.t) *50 ) +60+ "px",

//"height" : ( Math.cos(Ball.t) *50 ) +60+ "px",

});

Ball.t = Ball.t+ 0.1;

},30);

},

stop : function(){

clearInterval(Ball.interval);

Ball.interval = null;

}

}

$(document).ready(function(){Ball.init();});

 

 

----------------------- HTML --------------

<div id="wrapper">

<div id="box">

<img id="ball" src="ball.png" />

    </div>

</div> 

댓글목록

등록된 댓글이 없습니다.