How to make race effect?

Asked

Viewed 521 times

1

I need to put an effect on the cars so they can move up to that point when I load the page.

You got any Jquery for that? I don’t even know if you have a name for it

I also have to put this edge on the cart, as is the example of the first (on the right).

What’s the best way to do that?

carros de corrida

inserir a descrição da imagem aqui

  • What format do you have that(s) images?

  • @Sergio are in a PSD! can save as PNG

  • @Hendyalmeida So, first you have to separate the image of the cars from the background image, if you have the PSD you will probably be able to do this, if you have a link with the images I can do and reply here

  • I added the cart image! (:

2 answers

5


You can use the styles transform and transition. The first can be used to move (easily and more browser friendly) elements on the screen. The second serves to declare that you want to animate changes to certain styles (in this case, the transform).

/* Os carros começam fora da tela */
.carro {
    /* movimenta o elemento no eixo X */
    transform: translateX(-2000px);
    transition: transform 1s;
}

/* Utilizando js, você adiciona uma classe para utilizar como seletor para deixar os carros na posição correta */
.largada .carro {
    transform: translateX(0);
}

To start the animation, using the code above, simply add the class largada in a container above the cars.

A hint is also using the style transition-delay that adds a delay before the animation starts. So you can increase the delay for each car by giving a little more life to your animation.

Example in jsFiddle

  • 1

    It worked! Obrgada (:

2

You can do this with CSS and Javascript.

In CSS you define the transition you want to make and a class that defines the new value of for example margin-left:

#carros img {
    margin-left: -600px;
    transition: margin-left 1s;
}
.chegada {
    margin-left: 0px !important;
}

and in Javascript only need to add this CSS class after some time (3s in the example below):

setTimeout(function () {
    document.querySelector('#carros img').classList.add('chegada');
}, 3000);

Example: http://jsfiddle.net/uy0ajo3k/1 (now with suffixes for older browsers)

To do the effect of the car with the yellow border I suggest you have two different images and overlap the second that has this yellow color after.

  • The effect only happens when I shoot margin-left: -600px by browser :/

  • How Transition Works?

  • @Hendyalmeida what browser are you using? see image moving after 3 seconds of page load?

  • Chrome! In the example the effect works, but not in my project !

  • Can you put your project code? or better: adapt jsFiddle with your code to reproduce the problem and put it here...

  • 1

    I managed to solve it! Thanks for the help, I need to study more :D

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.