javascript - algorithm/formula to move elements so they reach a specific x and y coordinate at same time -


I want to take a div 70% left and 10% above my viewport when I scroll My code for here is:

  flowers. Protopp Animatablemeframe = function () {var scrolls = window. PageWay Offset / Window.VerHeight * 100; // Check if the next keyframe has to be loaded (! This.animationDone) {// var formula = (this.initialPos.top - this.keyframe ['top'] * percentage hight) / (this.initial. Pos.left - this .keyframe ['left'] * percentage) * (scroll * 5); / * * Animate the top spot / / (If this .pop.tap> gtight = * this.keyframe ['top']) {this.domEl.css ('top', (this.initial.pos .top - (* scroll .speed) + 'PX'); } And if (this.page.top and lieutenant; percentheit * this.keyframe ['top']) {this.domEl.css ('top', (this.initial.pos.top + (scroll * this.speed) ) + 'Pixels'); } / * * Animating * / if (this.pos.left & lt; percentwidth * this.keyframe ['left'] on the left) {this.domEl.css ('left', (this.initial.pos.left + (Scroll * This.speed) + 'PX'); } Else if (this.pos.left>% Width * this.keyframe ['left']) {this.domEl.css ('left', (this.initial.pos.left - (scroll * this.speed )) + 'Pixels'); } / * * Animating rotation * / this.domEl.css ('transform', 'rotated (' + (this rotation + (scroll * SPEED) 'degree)'; This.domEl.css ('- WebKit- Transform ',' Rotate when ('+ (this rotation + (scroll * this speed) +' degree) '; / * * Update and check status * / this.pos = this.domEl.position (); Var LeftDone = this.pos.left> (Percentwid * this.keyframe ['left'] - 5) & amp; amp; amp; amp; amp; amp; amp; amp; this.pos.left & lt; (Percentwind * this.keyframe ['left'] + 5 ); Var topDone = this.pos.top> (percentile * this.keyframe ['top'] - 5) & amp; amp; amp; amp; amp; amp; this.pos.top <(percentile * this.keyframe ['top' ] +5); If (top don & left) {warning ('fertig!' + This.num); This.animationDone = true;}} and {this.getKeyframe ();}  

This keyframe is an object: {left: 70, top: 10, rotation: 100}. But when I scroll, the element is increasing with the X and the Y axis, although I want both CSS -The soldiers should move in such a way that they both reach the goal (this.keyframe) at the same time. Otherwise it comes first on the y-axis and later on the x-axis.

I tried to realize that with the linear equation as you can see here: // var formula = (this.initialPos.top - this keyframe ['top'] * percent hight ) / (This initial.pos.left - this.keyframe ['left'] * percentage) * (scroll * 5);

However I can not put the code in the top position and the left position is changing because it will move evenly again.

Do you have any ideas for me?

This is not the same effect - the movement is not linear - but when I make an object If I have to move in position, then I use continuous linear interpolation, such as:

  for (;;;;;;;;;;;;;;;;;;;;;;;;; ;; (Mathematics.babs (present xx - target.x) & lt; 0.1) {done ();} and {current.x = current.x * 0.9+ target.x * 0.1; Current.y = present Y * 0.9 + target y * 0.1; Current.a = current.a * 0.9 + goal. A * 0.1;}}  

this is the same on both axes Time will reach the destination.

If you still want linear movement, then your attitude is fine, but you have to calculate the speed for every variable (every axis).


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -