animate menu: shall I use canvas or javascript?

Harmonia

I must animate my main menu links ( About us, contact, etc) which have specific graphics (I am using anchor with a background image class). I'm wondering if canvas is the best way to animate a specific div (my menu). I just want to move it 100px upward/downwards after being clicked. For example: I click "Projects", my anchor (with my image) is moved 100 pixels down. When I click "About Us", the "Projects" link is moved up (at it's original position), and "About us" is moved down 100px.

Is canvas the right way to do it? I could also use css3 transitions/animate but IE9 is not supported. I want IE9 to be able to render my site correctly.

Shall I use canvas or some kind of javascript plugin for this? ( I could also use plain javascript with relative/absolute positioning that keeps changing top pixels, but I don't like the result of it). What I used with plain javascript was this:

My menu:

 <div id="menu">
   <ul class="nav">
        <li><a href="#" class="projects" id="projects" onclick="move()"></a>
        </li>

        <li><a href="#" class="aboutus"></a>
        </li>

        <li><a href="#" class="contact"></a>
        </li>
   </ul>

My CSS:

 a.projects 
 {
     width: 184px;
     height: 32px;
     background: url('css-images/projects.png') no-repeat;
         position: absolute;
 }
#menu
{
    position:relative;
}

My javascript:

 function move(){
     var proj = document.getElementById("projects");
     var count = 0;
     var id  = setInterval(loop, 30);

     function loop(){
         proj.style.top = count + "px";

         var max = 100;
         count+=10;
         if(count >= max){
        clearInterval(id);
         }
     }
 }
Ryan Williams

Go with jQuery's animate() function if broad browser support is required. If not, use CSS3 transitions.

If you're not concerned about how exactly your animations look so long as they're roughly equivalent, you could leverage Modernizr to deliver CSS3 animations to browsers that support them and jQuery animations to those that don't.

It's worth nothing that jQuery's animate() function could natively deliver CSS3 animations to eligible browsers, but jQuery's developers haven't yet implemented this. This is likely because browsers still implement CSS3 transitions with varying degrees of success, whereas jQuery is geared towards keeping things consistent.

Canvas isn't really appropriate for the use case IMO due to its abstraction from your semantic elements.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Shall I use static here or not?

From Dev

JavaScript animate sliding menu

From Dev

Shall I use "directive" or "controller" for this case?

From Dev

Shall I use POJO or JSONObject for REST calls

From Dev

How shall I use `docker rm -v`?

From Java

Shall I use WebSocket on ports other than 80?

From Dev

Which datatype shall i use to store image in database(PostgreSQL)?

From Dev

Shall I use Visual Studio Express or Visual Studio 2013?

From Dev

shall I use callback pattern in my custom function? node js

From Dev

VB.Net - when shall I use "New" word?

From Dev

Which java collection shall I use to store my data?

From Dev

Java programming to interfaces shall I use it all the time, especially for collections

From Dev

Shall I extend the service class or just use an instance of it?

From Dev

Shall I use package name or class name to reprensent a concept?

From Dev

VB.Net - when shall I use "New" word?

From Dev

shall I use callback pattern in my custom function? node js

From Dev

JavaScript: Shall I pass null into XMLHttpRequest.send()?

From Dev

How can I animate an image to spin inside an HTML5 canvas with JavaScript?

From Dev

Animate Javascript Canvas while in recursive calculation

From Dev

javascript canvas animate with setinterval or settimeout, reliable?

From Dev

Can I use PHP wordwrap in HTML canvas javascript

From Dev

Does the compiler automatically use GPU while compiling or shall I have to use it manually?

From Dev

When shall "row" be use in Bootstrap

From Dev

Shall I store GCM in database?

From Dev

shall I pass an object or a primitive?

From Dev

Animate Canvas Fill() From Bottom To Top Using JavaScript / jQuery

From Dev

Which annotation shall I use to keep spring boot from securing my Controller when actuator is active

From Dev

How shall I use fakesAync in Angular unit test when you make an HTTP call that returns an observable?

From Dev

my responsive for small medium mobile is not working?what property shall I need to use

Related Related

  1. 1

    Shall I use static here or not?

  2. 2

    JavaScript animate sliding menu

  3. 3

    Shall I use "directive" or "controller" for this case?

  4. 4

    Shall I use POJO or JSONObject for REST calls

  5. 5

    How shall I use `docker rm -v`?

  6. 6

    Shall I use WebSocket on ports other than 80?

  7. 7

    Which datatype shall i use to store image in database(PostgreSQL)?

  8. 8

    Shall I use Visual Studio Express or Visual Studio 2013?

  9. 9

    shall I use callback pattern in my custom function? node js

  10. 10

    VB.Net - when shall I use "New" word?

  11. 11

    Which java collection shall I use to store my data?

  12. 12

    Java programming to interfaces shall I use it all the time, especially for collections

  13. 13

    Shall I extend the service class or just use an instance of it?

  14. 14

    Shall I use package name or class name to reprensent a concept?

  15. 15

    VB.Net - when shall I use "New" word?

  16. 16

    shall I use callback pattern in my custom function? node js

  17. 17

    JavaScript: Shall I pass null into XMLHttpRequest.send()?

  18. 18

    How can I animate an image to spin inside an HTML5 canvas with JavaScript?

  19. 19

    Animate Javascript Canvas while in recursive calculation

  20. 20

    javascript canvas animate with setinterval or settimeout, reliable?

  21. 21

    Can I use PHP wordwrap in HTML canvas javascript

  22. 22

    Does the compiler automatically use GPU while compiling or shall I have to use it manually?

  23. 23

    When shall "row" be use in Bootstrap

  24. 24

    Shall I store GCM in database?

  25. 25

    shall I pass an object or a primitive?

  26. 26

    Animate Canvas Fill() From Bottom To Top Using JavaScript / jQuery

  27. 27

    Which annotation shall I use to keep spring boot from securing my Controller when actuator is active

  28. 28

    How shall I use fakesAync in Angular unit test when you make an HTTP call that returns an observable?

  29. 29

    my responsive for small medium mobile is not working?what property shall I need to use

HotTag

Archive