background preloader

Div animation

Facebook Twitter

Using jQuery's Animate() Step Callback Function To Create Custom Animations. .animate. Description: Perform a custom animation of a set of CSS properties.

.animate

The .animate() method allows us to create animation effects on any numeric CSS property. The only required parameter is a plain object of CSS properties. This object is similar to the one that can be sent to the .css() method, except that the range of properties is more restrictive. Animation Properties and Values All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used).

In addition to style properties, some non-style properties such as scrollTop and scrollLeft, as well as custom properties, can be animated. Shorthand CSS properties (e.g. font, background, border) are not fully supported. Animated properties can also be relative. Duration Complete Function Basic Usage. How to create custom jQuery easing functions - Some code from seamusleahy. It is not hard to make your own easing functions for jQuery animations (which the jQuery Easing Plugin provides many useful ones).

How to create custom jQuery easing functions - Some code from seamusleahy

You just have to add your function to the jQuery.easing object. Your function receives five arguments and then it returns a number with 0 being the start and 1 being the end. You can go below or above this range if you want a bounce type effect. The tricky part is figuring out what the function arguments are because they always have cryptic names; but they are straight forward once you know. t - the percentage of how much time has passed in the animation: 0 is the start of the animation and 1 is the end of the animation. You can see an example of a custom easing function here that over-shoots and comes back. jQuery Animations with automatic CSS3 transitions when possible.

Anton: Drawing a diagonal line in HTML/CSS/JS (with jQuery) In my case, I have an organisation chart with nodes, which allows the user to connect the nodes visually.

Anton: Drawing a diagonal line in HTML/CSS/JS (with jQuery)

A way I solved it so far is have a “link” icon on each node, when the user presses it they switch to “link mode” — an on-screen line starts at the origin node and follows the mouse cursor, until the user clicks on another node (or right-clicks / presses Escape to exit the link mode). So how do I draw that line between arbitrary points A and B on the webpage? The answer: Just draw it and rotate it. Warning — details below may contain traces of math, please be careful if you're allergic to it. Though its density is so low that it is unlikely to hurt anybody, honest! Details First of all we need to establish that HTML blocks are rectangles. Here's the initial CSS style for this link line: This is a 3-pixel-wide rectangle with no height set. // Assign the mouse move event $(document).mousemove(linkMouseMoveEvent); Next and last step is to calculate the rotation angle.

Edit fiddle. Why moving elements with translate() is better than pos:abs top/left. In modern days we have two primary options for moving an element across the screen: using CSS 2D transforms and translate()using position:absolute and top/left Chris Coyier was asked why you should use translate.

Why moving elements with translate() is better than pos:abs top/left

Go read his response which covers well why it’s more logical to move elements for design purposes (with transform) independent of your element layout (with position). I wanted to answer this with Chrome and get some good evidence on what’s going on. I ended up recording a video on the experience: It’s a good watch and dives into Chrome DevTools’ Timeline, compositing, paint cost, accelerated layers, and more… but if you want the abbreviated text version, read on: First thing, Chris made some simple demos to try things out: This sorta works, but there is such low complexity in this situation that it’s all going to look pretty great.

Now we’re starting to get closer, but immediately I get distracted by something. Draggable.