HP. HP. - 3 months ago 40
HTML Question

Tricky Button Moving Away when Mouseover in Javascript?

I remember seeing some website or script on the web about this funny / tricky button: Basically it's a button that is impossible to click. When mouseover, it moves randomly away.

Can someone point me to a source or show me few line of code to do that? Preferably using jQuery.

Answer

This is probably what you are looking for, http://jsfiddle.net/9CDtE/4/

HTML

<button>button</button>​

CSS

button{
    position:absolute;
    top:10px;
    left:10px;
}​

JS

$(function(){
    $("button").on({
        mouseover:function(){
            $(this).css({
                left:(Math.random()*200)+"px",
                top:(Math.random()*200)+"px",
            });
        }
    });
});​