views:

56

answers:

3

I came a across a really sharp intro effect I'd like to try and create in jQuery, mootools or prototype: http://www.johndigweed.com/ (Just the spin in effect) So in a sense, I want to spin in the main content div of the page.

Any suggestions to get started or are there base plug-ins that have help achieve this intro effect outside of flash? Or is this effect even feasible to to do with JavaScript?

I am a noob with JavaScript so many Thanks!

+1  A: 

As a general rule, assume something is possible until you've given yourself a concussion with the desk.

Anyway, it is possible to do javascript based animation, the simple stuff has already been implemented in jQuery and the like (slides and fades etc).

My initial research has led to believe that this kind of animation currently only possible with webkit browsers (and IE, using a very different method and linear algebra). There is a webkit style called -webkit-transform that has a value 'rotate()'

You can set the rotation (using jQuery here because its what I know) like this:

jQuery("#div").css('-webkit-transform', 'rotate(20deg)')

The deg bit is important otherwise it doesn't work (you can also use radians by using rad instead of deg)

Remember that this will only work in webkit browsers, meaning safari and chrome. Mozilla might have a similar method you can use.

Aatch
+1  A: 

For that effect you can use the following jQuery plugin.

http://code.google.com/p/jquery-rotate/

After you include jQuery and this plugin you can simply do something like:

function rotation() {
    //being #theimage the element id that you want to rotate
    $('#theimage').rotateRight(45);
}

$("document").ready(function(){
    setInterval("rotation()",1000);
});

This code is very simple to understand. After the document is ready (DOM is ready), you are simply going to call the function rotation() every 1 second. And each time rotation is executed you rotate your image 45 degrees.

This is even easier to do this HTML5 canvas. If you want I can post the code to do that.

João Gala Louros
does HTML5 render this effect faster than JavaScript?
Mikey1980
Please try to use Markdown correctly - see the formatting guide at http://stackoverflow.com/editing-help.
Yi Jiang
Thanks Yi Jiang, I had some problems using Markdown correctly.
João Gala Louros
Mikey1980. The effect required to do this animation in HTML5 is actually and mix with HTML5 canvas and JavaScript. Anyway if you try to use HTML5 it will be fast because you are not including any external JavaScript library, which in the large majority of cases will be faster. But as you may know it won't be support by older browsers.
João Gala Louros
+2  A: 

It won't work on every site and any browser yet, but it's a start:

var i = -90,
    ii = -900,
    timer,
    body = jQuery("body");

function rotation() {
    body.css({
        '-moz-transform': 'rotate('+(i++)+'deg)',
        top: (ii+=10) + "px"
    });
    if(i>0){
        clearInterval(timer);
    }
}

body.css({
    '-moz-transform': 'rotate('+i+'deg)',
    top: ii+"px",
    position: "absolute"
});

timer = setInterval(function(){rotation();}, 100);
jerone
+1 awesome, combine that with Aatch's answer and all that leaves is IE, many thanks!
Mikey1980
Nice. Just keep in mind Mickey that this does move the entire site, narrow down your identifier if you want somethings to be static.
Aatch