Git Product home page Git Product logo

jquery.path's Introduction

jQuery.path

Provides animation along bezier and circular arcs.

The animation engine in jQuery is focussed on single dimensional animation - hence it's difficult to animate two variables along a path.

This simple plugin provides a method of multidimensional animation, and in particular provides a method for animating along bezier curves and arcs.

Bezier

Example: animate along a bezier path

var bezier_params = {
    start: { 
      x: 185, 
      y: 185, 
      angle: 10
    },	
    end: { 
      x:540,
      y:110, 
      angle: -10, 
      length: 0.25
    }
  }
  
$("my_elem").animate({path : new $.path.bezier(bezier_params)})

Bezier curves are made form a start point, an end point each with a control point

  • start is starting point
  • end is the final point
  • x,y indicate the coordinates at that point. Required
  • angle is the angle of the control point from the line joining the start and end. Optional, default is 0
  • length is the distance from the point to it's control point as a ratio of the distance from start to end. Optional, default is 1/3

Arc

Exampe: animate along an arc

  
var arc_params = {
    center: [285,185],	
		radius: 100,	
		start: 30,
		end: 200,
		dir: -1
  }
  
$("my_elem").animate({path : new $.path.arc(arc_params)})
  • center is the coords of the centre of an imaginary circle that contains the start and end point
  • radius is the radius of this circle
  • start is the angle of the start point. 0 is "North", measured clockwise
  • end is the angle of the start point. 0 is "North", measured clockwise
  • dir is the direction to move in. Only required if not obvious from start and end (e.g. if start is 100, end is 30, but you want to animate clockwise)

Other Paths

It is trivial to create other paths, or even animate other parameters. E.g:

var SineWave = function() {
  this.css = function(p) {
    var s = Math.sin(p*20)
    var x = 500 - p * 300 
    var y = s * 50 + 150
    var o = ((s+2)/4+0.1)
    return {top: y + "px", left: x + "px", opacity: o}
  } 
};
  
$("my_elem").animate({path : new SineWave})

Links

Compatibility

Tested in

  • Firefox 3.5
  • Safari 4
  • IE 6, 7, 8

jquery.path's People

Contributors

weepy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.path's Issues

demo not working - missing html tag?

I noticed the demo (which I seem to recall working in the past) isn't working. It looks like it's missing the opening <html> and <head> tags.

License

I don't see any license and I wanted to use ur code in commercial project. Please, I just need a note if I cannot use it or need to w8 for info about license.
Thanks in advance

Resume animation

I find this is very difficult to resume an arc animation.

Upon resuming the animation, I start the animation from the end angle and stop at the angle I wanted, but, somehow, I get "NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMWindow.getComputedStyle] in", when I request a new animation from the first animation end angle.

Have anyone tried to solve this?

What is the p parameter in the SineWave function?

I think a sine wave animation is very useful, but the documentation doesn't explain clearly what the p parameter is and where it comes from. It is also unclear how to program the beginning and end points of the movement.

custom path

how can I draw custom paths?
like;

start 100,100 , go 200,100 and go 300,100 and finish 400,100.

Getting error $.path is undefined

function animate()
{
  var path = {
            start: {
              x: 50,
              y: 50,
              angle: 315.012,
              length: 0.707
            },
            end: {
              x: 540,
              y: 540,
              angle: 315.012,
              length: 0.707
            }
          };

  $('.animatingDiv').animate(
      {
        path : new $.path.bezier(path)
      },
      2000,
      animate
    );
}

Trying above code but getting - TypeError: $.path is undefined

Thanks

End values after first animation as start values the second time?

Hi!

I'm experimenting with this plugin (great work!) and I find it very useful.
Now I'm working on a small demo where I want to be able to run the animation several times in a row and have the end position of the element I animate become the start position the next time I run the animation - like a wheel of fortune.

Is there a way to accomplish this?

Regards,
Thomas

Units & scale

Is it possible to add the units as an option? It has worked when I edit the file and replace "px" with "%".

Also I would like to know if a mutiplier can be specified, say for Arc, so as to create a Oval either on X or Y.

Thank you :)

How to not repositionning elements?

I would like to move items from their position I defined in relative and not in a redefined position. Is there a way to do that? I'll be grateful if you could help me :-)

Resetting the direction

I've created a demo that, upon user initiation, animates objects on a path. When animation is finished, I am reasetting the start and end positions so that upon another click the objects will start at their current position and move the same incement as before around the path.

The problem I'm having, however, is in attempting to reverse the direction. Whereas I can reset the start/end it seems that resetting the 'dir' has no effect on the animation.

Easy fix to be able to reset this parameter?

Thanks.

Can i stop animation before ending point?

Hi i created animation of unfolding cards along a one bezier curve.
Can i stop animation before ending's point?

I would need to position the cards like a folding fan

Stop on point

I'm trying to stop an object on a point or percentage of the length of a path. I was wondering if there is a feedback loop for object's current position or simpler way to do this using your plugin.

Demos are not working in latest Chrome

I'm not sure if this repo is still being maintained, it looks like the last activity was several years ago.

I'm using Chrome 37.0.2062.124 and getting console errors: Uncaught TypeError: Cannot read property 'arc' of undefined

Not working in Chrome Version 33.0.1750.154 m (latest version)

Reversed SineWave

Hey,
I am using slightly modified version of your SineWave which does the same as yours. On event my bubble starts moving by the SineWave path, any ideas how would I later on reverse that path by another event.

So from point A to B with SineWave and later on from point B to A with same path?

Simple Demo

It would be great to see a SIMPLE demo. Maybe using a single image or div...

I've been trying to deconstruct your code for about 2 hours now and I, nor any other the people sitting near me, are able to figure out why your code works and ours does not.

How can I continue animation from point I stopped it ?

Made script - several circles move arond one circle - animate along an arc.
I stop this animation by "stop" method when "mouseover", but how can I continue when "mouseleave". I just need to get current angle. How can i get it ? Thanks for help!

Rotate element along path in line with bezier angle?

jquery.path is perfect for my needs, but it's missing one little piece. What might be the best way to implement jquery rotate to change the angle of the element set to follow the bezier path, and to keep it's angle in line with the path?

http://code.google.com/p/jqueryrotate/

If you had an image of a car, animated to follow the contours of a hill, you'd want the image element to rotate as well, and there should be enough data to divine the proper angle (given the correct offset) inside the bezier animation function, I just can't seem to figure out what is what.
Any ideas?

Multi sine path and infinite loop

hello
I need to create sine style with multi cyrcle and start automaticly without stop cyrcles (infinite loop)
how can i do this ?

360 loop using Arc

I have tried to go from degree 0 to 360, or from 0 to 0, using dir: -1 and it doesn't work, and same issue trying to go from degree 360 to 0, or from 0 to 0, using dir: 1. I have solved it just modifying following lines, adding equal (=) to the comparisons:

while ( this.start >= this.end && this.dir > 0 ) {
  this.start -= 360;
}

while ( this.start <= this.end && this.dir < 0 ) {
  this.start += 360;
}

how can I draw lines?

how can I draw lines?

I cant quite understand how can I draw custom path :(

examples not simple lines. can you add simple line example ?

thank you.

How to animate along on oval

Trying to find a way to animate the center point of arc down, then up within the same timeframe that an arc completes 360ΒΊ. This would theoretically create an oval shape. I've tried chaining animate marginTop chains, etc etc but just can't get it to work right. Would love to be able to just provide an argument to the center point of the arc to offset the circle and get the same effect... possible?

Issue with Safari 6.0.2 and Firefox 17.0

There seems to be some bezier path animation display bugs / inconsistencies with Safari 6.0.2 and Firefox 17.0. The animation renders smoothly in the latest build of Google Chrome but is jumpy and inconsistant in Safari and Firefox.

Here is the code I am using:

https://gist.github.com/4171190

Note: I am not 100% certain if the bug is originating in my bezier path code or if is definitely a browser compatibility bug.

Thanks,

Calvin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.