Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a run away button in jQuery

Tags:

jquery

I wanted to create a page with a simple button which runs away from the user when he tries to click it. Lets call it the Run away button?

Is there a simple 'jQuery' snippet which will allow me to do the same?

Regards, Karan Misra

like image 681
kidoman Avatar asked Apr 01 '10 04:04

kidoman


2 Answers

$('button').hover(function()
{
    $(this).css('top', rand(1,1000) + 'px').css('left', rand(1,1000) + 'px');
});

No plugin needed.

like image 106
Amy B Avatar answered Sep 27 '22 21:09

Amy B


Catch me if you can

alt text

<button id="theRunAwayButton"></button>
button {
    position: absolute;
       background: url(http://t0.gstatic.com/images?q=tbn:6JxQilywV2GyxM:http://images.clipartof.com/small/7038-Baseball-Mascot-Cartoon-Character-Running-Poster-Art-Print.jpg);
    width: 127px;
    height: 111px;
}
var width = $(window).width() - 127;
var height = $(window).height() - 111;

function run() {
    var top = Math.random() * height;
    var left = Math.random() * width;
    $('#theRunAwayButton').css('top', top + 'px').css('left', left + 'px');
}

$(document).ready(function() {
    $('#theRunAwayButton').mouseover(run);
    $('#theRunAwayButton').mousemove(run);
});
like image 36
Erric J Manderin Avatar answered Sep 27 '22 22:09

Erric J Manderin