Git Product home page Git Product logo

jquery.transform.js's Introduction

jquery.transform2d.js adds 2d transform capabilities to jQuery css() and animate() functions.

Demo

Usage:

Set transform with a string

$(elem).css('transform', 'translate(50px, 30px) rotate(25deg) scale(2,.5) skewX(-35deg)');
$(elem).animate({transform: 'translateY(-100px) rotate(1rad) scaleX(2) skewY(42deg)'});

You can use the following list of transform functions:

  • translateX(<number>px)
  • translateY(<number>px)
  • combined: translate(<number>px, <number>px) the second number is optional and defaults to 0
  • scaleX(<number>)
  • scaleY(<number>)
  • combined: scale(<number>, <number>) the second number is optional and defaults to the value of the first one
  • rotate(<angle>) units for angles are rad (default), deg or grad.
  • skewX(<angle>)
  • skewY(<angle>)
  • matrix(<number>, <number>, <number>, <number>, <number>, <number>)*

*matrix gives you more control about the resulting transformation, using a matrix construction set.
When using it in animations however, it makes it impossible to predict how the current and target transformations are going to be interpolated; there is no way to tell whether elements are going to rotate clockwise or anti-clockwise for instance.

Get transform

returns a computed transform matrix.

$(elem).css('transform') == 'matrix(0,1,-1,0,100,50)';

Relative animations

Relative animations are possible by prepending "+=" to the transform string.

$(elem).css('transform', 'rotate(45deg)');
// using the following syntax, elem will always rotate 90deg anticlockwise
$(elem).animate({transform: '+=rotate(-90deg)'});

Limitations:

  • requires jQuery 1.4.3+,
  • Should you use the translate property, then your elements need to be absolutely positionned in a relatively positionned wrapper or it will fail in IE,
  • transformOrigin is not accessible.

Why such restrictions with 'translate'?

Since translate is unavailable in IE<9, we have to emulate it using top and left properties of the element style.
This can, of course, only work if the elements are absolutely positionned in a relatively positionned wrapper.

Other plugins position the elements and wrap them transparently.
I think that transparently messing with the DOM often introduces unpredictible behavior.
Unpredictible behavior leads developpers to fear plugins.
Fear leads to anger. Anger leads to hate. Hate leads to suffering.
I prefer leaving this up to you.

License

Dual licensed under GPL and MIT licenses.

Copyright (c) 2010 Louis-Rémi Babé.

jquery.transform.js's People

Contributors

clorr avatar gilmoreorless avatar louisremi avatar timgluz 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.transform.js's Issues

RotateX, RotateY Support

Hey, was wondering if you have any plans of adding animation support for rotateX or rotateY to the 3d transform library? Would be extremely useful!

Thanks and awesome library.

Releases

It would be easier to use this plugin with Bower if it had tagged releases.

Accept Percentage Values for Transform

Just like the title says. I do off canvas type animations moving things out and then back into the viewport using percentage values from time to time. Would be great to accept percentage values for transforms instead of just pixels.

Weird rotate animation

When I rotate element from 180deg to 270deg it rotates anticlockwise instead of clockwise. Also when I rotate from 360deg to 450deg it makes full circle before rotating 90 deg. It looks weird. If you fix this bug, it will be great.
Thanks.

Rotate errors - IE8 - 'this._container.style' is null or not an object, 'this._img.parentNode' is null or not an object

On IE8 (genuine IE8 not IE9+ in IE8 mode, windows 7), the four simple demos on your demo page don't run, and this error is in the console:

image

The 'Advanced usage' demos do seem to work, however.

I tried making my own demo on jsbin and it fails with identical errors: http://jsbin.com/ejiqov/1

[Strangely, after the first time I ran the script, it stopped failing with an error message - but started failing by ignoring the top: and left: values set by CSS. Edit- this second sub-issue can be solved by applying the positioning to an outer wrapper element and then applying the rotation to an inner element - but it would be nice if the transform calculation could take existing CSS top:, left: etc into account - working demo here http://jsbin.com/ejiqov/3 ]

Rotate has issues animating well

http://jsfiddle.net/EvsVJ/

When you switch to the newer version of the plugin, css() works but the subsequent animate() does not. I have only noticed this wackiness when dealing with rotate—scaleX and translate (the other ones I have tried) have animated just fine.

Fix percent usage

Using transform: 'translate(0, -50%)', is replaced to transform: 'translate(0, -50px)',

Scale animation failing on IE9

On IE9, the following works as expected:

$(elem).css({transform: "scale(0.5, 1)"})

But, the following produces no results:

$(elem).animate({transform: "scale(0.5, 1)"})

(This works in Firefox, Safari, and Chrome, just not IE 9.)

I've tested this with both JQuery 1.6.2 and JQuery 1.7.

scaling within a div

When I scale down, the content get's pushed down.

When I scale up, the content get's pushed up past the top of the div.

Is there a way to make the content get pushed to the top of the div?

Also, is there a way to disable the use of the scalable content moving left and right when zoomed in?

[enhancement] Add missing bower.json.

Hey, maintainer(s) of louisremi/jquery.transform.js!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library louisremi/jquery.transform.js is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "louisremi/jquery.transform.js",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

why don't you support transform3d?

This library is an awesome!

But, this libray is not support tranform3d property.
to improve performance, I use a translate3d property frequently.

Do you have a special reason that not support transform3d property?
Do you have a plan to support transform3d property?

Any relative or abs positioning on descendants breaks scale only on IE8

I have a slider with multiple slides that I wan't to scale on window.resize. The problem is with IE8. On all other browsers, including IE7, when the #slider_wrap is scaled, its children are scaled as well.
But on IE8, when I apply the scale transform only the #slider_wrap is resized, none of its children.
After some debugging I found that this happens if any of the children are relatively or absolutely positioned. When all the position rules are removed from children, the scale transform works, but it breaks my slider layout.
This is my slider layout:
#slider_wrap(absolute)
#slider(relative)
#slides(relative)
.slide(absolute)
I must remove all the positioning below #slider_wrap to get scale to work. Is there any help, other than reworking this custom slider that we use?

transform2d broken in Firefox Nightly

"skew" has been removed for the list of transform functions and this evolution in the spec has already been followed by Mozilla in Firefox Nightly: http://t.co/Wq1eaGtr

As a consequence, jquery.transform2d.js is broken in this browser.

If you use this script, you should be concerned!
You can help me solve this problem by posting a link to your website here.

I'll update my plugin, before the end of the week hopefully.

Multiple Filters Pt. Deux

Actually, I totally lied with my previous comment. I made a mistake while linking from my Dropbox account and did not include the latest version.

Currently-existing filters are still over-written in IE<9: http://jsfiddle.net/22Nac/

Relative transformation and transform.light

I cannot get relative transformations working with the light-version. With the non-light version it works fine.

If I first do

#myDiv{
  transform: "scale(0.3)";
}

and then do

var current = $("#myDiv").css("transform");
$("#myDiv").animate({transform: current+"scale(2)"});

the div jumps to original size and is then scaled to double size, instead of being scaled from 0.3 to 0.6.

Chrome Dev/Safari 5.1 OS X Lion, JQuery 1.6.2

No workie in IE<8, analysis within

suffix = propertyName[0].toUpperCase() + propertyName.slice(1),

IE<8 doesn't support treating strings like arrays, throwing undefined.

Setting suffix to simply 'Transform' fixes this and everything works awesome (amazing job!), but I assume there's a bigger reason why you defined it this way.

only left and right

Is it possible that the pictures only move on a horizontal line and not up/down on the vertical line?
So that "liked" is only on the right frame (not upper right or bottom right) and "nope" only on the left side…
And second: I don't need the skewing of the pics, how can I get rid of it?

Thx for any help!

not working with jquery animate

the old jquery.transform.light.js works good but this new version with transform2d and transform3d doesn't work for me... it works when I assign css with jquery but with animate it only does the first animation not the subsequent changes...

bower.json specifies invalid jquery version

$ bower install jquery-transform
bower cached        git://github.com/louisremi/jquery.transform.js.git#fd77c2207b
bower validate      fd77c2207b against git://github.com/louisremi/jquery.transform.js.git#*
bower not-cached    git://github.com/jquery/jquery.git#1.42
bower resolve       git://github.com/jquery/jquery.git#1.42
bower ENORESTARGET  No tag found that was able to satisfy 1.42

Presumably that should be 1.4.2 (or 1.4.3, to match package.json).

Offset or Position after a rotation is not correct in firefox

I you rotate an input box and you then try to get its new position using $(element).position().top or $(element).offset().top it will return the original position vs in IE and Chrome it will give you the new position.

Here is an example: http://jsfiddle.net/shrage/Xv39G/
Click on animate
Then click on "Left position of animate button" and you will see that it returns 18px which is the left position of the buttons original place. in chrome it will give you 400 which is the new position of the button after rotation.

bad control character

file: jquery.transform.js
line: 185
pos: 50

deleting and adding new whitespace fixes.

Error: missing ; before statement
SRC: jquery.transform.js
ROW: 178, COL: 51
Source:
propertyGet = propertyHook && propertyHook.get ||Â $.css;

callback events?

Is it possible to have some kind of callback functions, fired when the animation is complete?

Not working in IE8, Not animating in IE9

Having some trouble getting this working in IE8 and 9.

At the moment I've got it working perfectly in IE6/7, Chrome and Firefox. I'm creating an outer element for positioning (a list-item set to absolute) and I have an inner div that I apply the actual transformations to.

For some reason, the transform are not applied at all in IE8. I've uploaded two screenshots, the first is the transform working in IE9:

http://www.richardson.co.nz/bugs/working.png

and not working in IE8

http://www.richardson.co.nz/bugs/not_working.png

Secondly, the animations don't seem to be working in IE9. The regular jQuery animations work but the scale animation doesn't.

The code I use to initially place the items is as follows.

        // set position and scale of each of the panel items
        this.each(function(count, element, index, scale, left, zIndex) {
            var $element = $(element);

            // set position
            $element.css({
                position: "absolute",
                left: left,
                zIndex: zIndex
            });

            $element.find('.transform').css({
                transform: "scale(" + scale  + ")"
            }, {preserve: true});

        });

The code to animate the panels:

        this.each(function(count, element, index, scale, left, zIndex) {
            var $element = $(element);

            $element.css({
                zIndex: zIndex,
                display: 'block'
            });

            $element.animate({
                left: left
            }, {queue: false});

            $element.find('.transform').animate({
                transform: "scale(" + scale  + ")"
            }, {queue: false, preserve: true});

            if (this.isVisible(this.normaliseOffset(index))) {
                $element.css({display: 'block'});
            } else {
                $element.css({display: 'none'});
            }

        });

The HTML for a sample panel:

                        <li class="randomise">
                            <div class="transform">
                                <div class="image"><a data-reveal-id="modalVideo" href="#"><img src="static/strucimages/v2/homepage/things_to_do/1.jpg" alt="Youthfull Travellers"></a></div>
                                <div class="caption">
                                    <h4><a data-reveal-id="modalVideo" href="#">Video Item</a></h4>
                                    <p><a data-reveal-id="modalVideo" href="#">Choose Australia for a gap year, career break, or overseas study</a></p>
                                </div>
                            </div>
                        </li>

Add Version Number tag for CDNJS

I have requested your plugin to be added to CDNJS. Is there any way you could update this repo with a version number tag to satisfy their requirements?

problem when used with other animations

When running it with multiple animations, sometimes it doesn't execute the other animations, in this case the animation top

i've a code like this

var mypath = $("#myid");
mypath.stop().animate({top:0, transform: 'scaleX(2) scaleY(2)'},{queue:true, duration:400, specialEasing: {top:'easeOutExpo', transform:'easeOutExpo'}});

gives same problem with
var mypath = $("#myid");
mypath.stop().animate({transform: 'scaleX(2) scaleY(2)'},{queue:false, duration:400, specialEasing: {transform:'easeOutExpo'}});
mypath.animate({top:0},{queue:false, duration:400, specialEasing: {top:'easeOutExpo'}});

i've also tried another plugin like this, it gives same problem... any thoughts?

Looks like a code typo in the plug-in

On line 134 in transform.lite.js and line 151 in transform.js there appears to be a non-printable character (shows up as a space) between the '||' and 'elemStyle.filter'. It caused the plug-in to not work until I removed them. You might want to edit the plug-in.

-Anthony

Rotate not working in IE8

The rotate transform isn't working for me in IE8. It does work in IE9 and FireFox.

Example here: http://jsfiddle.net/E9vfj/

I had to inline jquery.transform.js to get it to work in the fiddle. This isn't necessary outside the fiddle.

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.