JQ animate 改变字体颜色()怎么改变<SVG style="fill:'red' ">的颜色

Cross Browser CSS Transforms – even in IE
March 9th, 2010 by zoltan &
(March 7, 2013) The examples on this page were missing due to a migration issue when upgrading my blogging software.
Thanks to James Wages for pointing this out.
(August 11, 2012) The skew() transform no longer works in Firefox, due to .
Developers must use the skewX() and skewY() functions instead.
The examples in cssSandaper, as well as this documentation, have been updated to reflect this change in the spec.
Thanks to , who gave a bug report on the cube example below that led me to find out about this.
(June 29th, 2011): cssSandpaper has been .
(August 28th, 2010) cssSandpaper now .
(May 6th, 2010): cssSandpaper has been .
(April 6, 2010): Please see the
which explores scripting CSS3 properties.
An example of a page using the CSS Transform property and cssSandpaper.
Visible in most major browsers, including Internet Explorer.
Layout based on work done by Paul Hayes in his article
allows developers to rotate, scale, and skew blocks of HTML via CSS.
Although you can do the same thing with images in Photoshop or The GIMP, using CSS transforms allows developers to do the same thing with any HTML markup and allows users to select the text within the transformed object.
When I first saw sites using transform, I looked at the underlying code and tried to produce pages using transform in all browsers.
Although Firefox, Opera and Webkit based browser support it via
(using -moz-transform, -o-transform and -webkit-transform respectively) Internet Explorer doesn’t support it at all.
I didn’t like that, so I took out my JavaScript whip, beat Explorer into submission and made it do my bidding (but not without getting a few mental bruises of my own).
Before I start talking about the details of my solution, let’s take a look at a few examples of it in action.
The following code has been tested with Firefox 3.5, Safari 4,
Chrome 4, Internet Explorer 6 and higher.
(The examples
also work on my copy of Opera 10.5, although I have seen it fail on other installations – I will update this post when I find
cssSandpaper to the Rescue
I saw the design potential of using CSS transforms and was frustrated at Explorer’s lack of support.
I originally tried a non-JavaScript solution which involved creating CSS rules that combine transform with an IE technology that does something similar: the .
I then, to steal a phrase from Russel Peters, started to Hurt Real Bad:
the syntax of transform is very obvious:
#myObject {
transform: rotate(40deg) scale(2.0);
but the IE filter code is quite intimidating:
#myObject {
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand',
M11=1.9554, M12=-1.0787,
M21=1.0796, M22=1.9558);
The scary numbers that the DXImageTransform.Microsoft.Matrix filter uses requires knowledge of matrix and vector mathematics.
Even though there is a , even the mathematically gifted wouldn’t want to do the calculations to do a simple rotate in CSS (I would like to note here that even though I have a university degree in Mathematics, I hate doing arithmetic inside my head.
If you don’t believe me, watch
me figure out a tip at a restaurant sometime.
I’m not kidding).
although it is possible to have a list of transformations using transform, the DXImageTransform.Microsoft.Matrix filter only allows one transform matrix. In order to implement multiple transforms using one filter,
a designer would have to .
Again, as ugly as I am when I first wake up in the morning.
when rotating, skewing, or doing any other transformations on objects using the transform property, the center of the object remains fixed.
However, the Matrix filter doesn’t keep the centre of the transformed object fixed, as seen by the illustration below:
Rotate using CSS transform
Rotate using IE Filter
I was about to give up on my endeavor until I read Weston Ruter’s clever
article, which implements gradients in older versions Firefox and Opera.
What I really liked was how he used the CSS from a web page to place the canvas gradients in the page (as opposed to using CSS classes to indicate where the gradients should go).
I then thought it would be a great idea to do the same with CSS transforms – why not have
JavaScript find out which objects are transformed by reading the style sheets containing the transform rules, and if the browser is Internet Explorer, apply the Matrix filter, while translating the image so that the center is maintained.
How hard could it be …….. right?
After a few obsessive months of coding, coffee drinking and Asprin popping (as well angrily asking myself on several occasions why the &@$! I would wanted to do this in the first place), I created cssSandpaper.js, a library that implements transform (and some other CSS3 properties) as consistently as possible in all browsers.
It uses many ideas from Ruter’s gradient script, as well as sylvester.js,
brilliant .
The code is currently in a beta stage, but I think that it’s in good enough shape that developers can start to play around with these really cool effects today and have it work in almost any browser.
Browser Differences
After I finished cssSandpaper and played around with transforms, I found some slight differences in the way browsers handled them:
If you transform an object with scrollbars, it is possible to scroll the object in most browsers in most cases.
However, in the cube page I mocked up, I noticed the following behaviour:
the left facing side of the cube isn’t easily accessible in IE.
the scrollbars don’t appear at all in Opera.
the scrollbars are not quite clear in Chrome for Windows, although one can still scroll the sides if you can guess where they are.
Firefox 3.5 for Mac puts the scrollbars in strange places (this has been fixed 3.6).
In Internet Explorer, the text is selectable but sometimes it takes a few tries to figure out how to do it (try selecting text with IE in my cube mockup and you’ll see what I mean).
When selecting text within Firefox, the text tends to jump around ever so slightly for some odd reason (this is quite a subtle effect that it is probably not noticeable in most instances).
It looks like Internet Explorer takes the block of HTML, converts it to an image and then does the transform (I’m not sure .. I’m guessing).
As a result, the text in certain situations will look a little blurry, especially if scaling is involved.
As to be expected, the rendering of the transformed text in the other browsers slightly differs:
Explorer 6.x+
Firefox 3.5+
Safari 4.0+
Chrome 3.0+
Opera 10.0+
Not Applicable
Doesn’t support transforms yet (as of version 10.50)
Not Applicable
Not Applicable
Doesn’t support transforms yet (as of version 10.50)
Using cssSandpaper
you must put the following tags into the head of your document after all of your style sheet declarations (this is to ensure the JavaScripts will run after the style sheets are loaded):
&script type="text/javascript" src="path/to/js/cssQuery-p.js"&&/script&
&script type="text/javascript" src="path/to//sylvester.js"&&/script&
&script type="text/javascript" src="path/to/js/cssSandpaper.js"&&/script&
You can then use the transform property in your web pages.
Note that since the specification for the transform property is finalized by the W3C, I decided to use the
-sand- before each CSS3 property it supports.
The following is a description of how to use transform, as well as two other CSS3 properties that cssSandpaper supports, box-shadow and gradient.
-sand-transform
Description
Transforms allow developers to rotate, scale, and skew blocks of HTML via CSS.
#container {
-sand-transform:
&function-list&;
where &function-list& can be a space separated list of the following functions:
rotate(angle)
Rotates HTML elements.
angle can be in degrees (e.g. rotate(30deg)) or radians rotate(1.3rad)
scale(sx[, sy])
Scales HTML elements.
sx and sy are numbers, where 1 represents the original size, 2 represents twice the size, etc.
Note that if sy isn’t specified, it is assumed to be equal to sx.
Similar functions are scaleX(sx) and scaleY(sy).
skewX(ax), and skewY(ay)
These functions skew the object around the x and y axes by the specified angles in degrees or radians.Note: the skew(ax, ay) function, which used to work in browsers that support CSS3 Transforms natively is no longer part of the W3C CSS3 spec and is no longer supported by Firefox.
matrix(a, c, b, d, tx, ty)
Applies a 2D transformation matrix comprised of the specified six values.
If you aren’t familiar with linear algebra and matrix arithmetic, this function will be hard to understand.
For further information, you may want to read
article, although if you are mathematically challenged, you may run away from your computer screaming.
If you are familiar with matrix multiplication, note that c and b are reversed.
This follows the way Firefox has implemented this method (i believe WebKit based browsers reverse these numbers).
Note: non-Explorer browsers support the translate function as well.
I have not been able to find a way to make this work IE at this time, due to a technical
issue with the IE’s Matrix filter property (for those who want details, I use sizingMethod='auto expand' when using the Matrix filter which doesn’t support translations, and using sizingMethod=’crop’ is not suitable to emulate the transform property).
For this reason, the tx and ty values of the matrix() function are not supported as well.
-sand-box-shadow
Description
box-shadow allows us to take a block level element and put a shadow underneath.
There can optionally set a blur factor to give a warmer effect to the shadow.
#container {
-sand-box-shadow: &horizontal-offset& &vertical-offset& &blur-radius&
Note that in IE, the blur-radius is not supported, due to a lack of support in IE’s .
-sand-gradient
Description
Gradients are gradual blends of color, and can be linear or radial:
#container {
background-image: -sand-gradient(&type&, &start-point&, &end-point&, &color-stop1&, &color-stop2&, ..., &color-stopN&)
The type can be linear and gradient, although Internet Explorer doesn’t support radial gradients at this time, due to limitations in IE’s .
Internet Explorer also only supports simple linear gradients (i.e. only
horizontal and vertical and only two colours).
A more detailed explanation can be found in the
Other Known Issues
Currently, when a users changes the font-size in IE, the layout gets a little messed up.
This will be fixed in a future release.
Scripting in IE cannot be done via the usual obj.style.transform.
There is, however, an alternative way of scripting the cssSandpaper supported properties which will be outlined in a future blog post (I don’t mean to keep anyone in suspense … it’s just that I feel like I’ve spent too much time on this post and I want to get at least this part out the door :-) ).
Opera 10.5 sort of works.
It works on my copy, but not on another copy I’ve seen.
I don’t know why yet, but I will find out soon and post and update when I do.
Weston Ruter’s gradient script has more features.
I will incorporate them in a future release.
Future Work
cssSandpaper will eventually be about more than just transforms – I would like to be able to support other advanced CSS topics (maybe even animations, if it is possible). It probably has a few bugs in it – I would really appreciate anyone letting
me know if you find any (my e-mail address is at the top left part of the page).
If anyone would like to get contribute code or do testing, I would love the help too.
Acknowledgments
I would like to thank Weston Ruter for his
script, since I stole many of his ideas with his permission (I will be implementing more of the advanced features of his script in a future release of CSS3Sandpaper).
I would also like to thank
for building
so I didn’t have to.
The script doesn’t handle :hover.
There is some work I need to do for this to work, but for now, it is not supported in cssSandpaper. :-(
The :nth-child issue is something it doesn’t recognize.
I’ll see if I can fix that.
It may be a limitation of cssQuery — perhaps I can look into supporting multiple selector libraries.
Again — thanks for the feedback.
If/when I do fix any of these issues, I’ll contact you directly.
Don't be shy! Give feedback and
join the discussion.
Please Note: If you are asking for help using the information on this page or if you are reporting a bug with the code featured here,
please include a URL that shows the problem you are experiencing along with the browser/version number/operating system
combination where the issue manifests itself.
Without this information, I may not be able to respond.
denotes a required field.SMIL in SVG
Introduction to&
SMIL animation in SVG
(

我要回帖

更多关于 js改变style属性 的文章

 

随机推荐