Vestige of mouse click

Asked

Viewed 136 times

4

I need a script, that on an entire page where a click appears a ball in the place where it was clicked, but that after a couple of seconds disappeared.

It doesn’t need to be ripples, just something that leaves a trace, an example is Google Maps when you click on the map appear white waves to say that you clicked here.

In place of the ball can also be a picture any.

  • Do you want this in any element of the page or in specific elements? If it is in specific elements just define a different [tag:css] for the links visited a:visited

  • In any element, but I don’t understand how the css you suggested could help me, even if it were in specific elements, could explain?

1 answer

6


You can create an element with absolute positioning, and use pageX and pageY to get the mouse click position. Then just put this element in that position:

$(document).click(function(e) {
    $(novoElemento).appendTo("body").css({
        position: "absolute",
        top:e.pageY,
        left:e.pageX
    }).show().delay(2000).hide(0); // O zero é importante, ou o delay não funciona
});

// Alternativa: setTimeout
var bola = $(novoElemento)...
setTimeout(function() {
    bola.hide().remove();
}, 2000);

Example in jsFiddle. (Note: my previous answer suggested clientX and clientY, but this does not work if the content is large enough to show the scroll bar)

  • Very good guy, but what I really wanted was that after some little time she(polka dot) disappeared.

  • 1

    @Samirbraga Just hide it (or remove it) after a while. I tried using .delay but it didn’t work, so here’s an example with setTimeout: http://jsfiddle.net/mgibsonbr/u96Cz/2/

  • Very good, thank you very much.

  • 1

    @Samirbraga I discovered the problem of delay: if you use hide without passing arguments, it applies immediately (i.e. shows and then hides). Passing a number of milliseconds, even if it is zero, it works as it should (only hides after the delay ends).

  • I put in the milliseconds, but thanks.

  • 1

    Very cool! But I couldn’t resist making one more "fresh" version with some effects. I’m out of votes now, but in about 3 hours +1 for the answer!

Show 1 more comment

Browser other questions tagged

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