0
원활하게 div (원) 이동하려고했지만 할 수 없습니다. Div가 즉시 마지막 지점으로 이동합니다.원활하게 마진 - 위쪽 div 설정
공이 떨어지는 과정을 시뮬레이션 해 보았습니다. 두 번째 매개 변수 0으로 메서드 animate를 사용했지만이 방법으로는 도움이되지 않았습니다. 어떻게 수행하나요?
"use strict";
function calculateH(h, t) {
return h - ((Math.pow(t, 2)*9.8)/2);
}
/**
* [getTrip function is calculate Y coordinates for the ball thrown down]
* @param {[number]} h [The height from which the ball falls]
* @param {[number]} t [Time elapsed from the beginning of the fall of the ball]
* @param {[number]} interval [EPS]
* @param {[number]} k [Ratio of height to screen height. It is necessary that the ball fell to the site bottom]
* @return {[array]} [Array of Y coordinates. {0, 0.2, 1.2 ... h}]
*/
function getTrip(h, t, interval, k) {
var calculations = new Array();
for(t; calculateH(h, t) > 0; t += interval)
calculations.push((h - calculateH(h, t))*k);
return calculations;
}
$('document').ready(function() {
var bol = $('#mycircle');
var h = 100;
var t = 0;
var interval = 0.001; // eps
/**
* [k is the ratio of height of the screen to start the ball drop height]
* @type {[number]}
*/
var k = ($(document).height()-bol.height())/h;
var calculations = getTrip(h, t, interval, k);
// Problem is there.
// I want animate of fell ball, but this code just move in last Y coord.
calculations.forEach(function(y) {
bol.css({'margin-top': y+'px'});
});
bol.animate({'margin-top': h*k+'px'}, 1); // prees to the bottom
});
https://jsfiddle.net/82agzc2e/4/
감사합니다. 왜냐하면 나는 시뮬레이션 된 물리적 현상을 원하기 때문이다. 1 초의 지연은 실제 모델을 깨뜨릴 것입니다 –
내 실험은 공 드롭을 완전히 자극합니다. 시간은 높이에 따라 다릅니다. 가속 자유 낙하를 보여줄 필요가 있습니다. –
그러나 당신의 소견은 '0.001ms'의 간격이 불가능하다는 것입니다. 그래서 당신의 애니메이션은 매우 느릴 것입니다. 나는 이것이 당신이 원하는 것이 아니라고 생각합니다. 일반적인 질문을 해결하려면, 당신은 자신의 재귀 루프를 만들어야합니다. 이렇게 : https://jsfiddle.net/82agzc2e/6/ @ KonstantinKulakov – eisbehr