在jQuery中创建一个逃跑按钮
我想用一个简单的按钮创建一个页面,当用户试图点击它时,这个按钮就会跑开。我们叫它逃跑按钮吧 是否有一个简单的“jQuery”代码片段可以让我做同样的事情 问候,, 卡兰米斯拉在jQuery中创建一个逃跑按钮,jquery,Jquery,我想用一个简单的按钮创建一个页面,当用户试图点击它时,这个按钮就会跑开。我们叫它逃跑按钮吧 是否有一个简单的“jQuery”代码片段可以让我做同样的事情 问候,, 卡兰米斯拉 $('button').hover(function() { $(this).css('top', rand(1,1000) + 'px').css('left', rand(1,1000) + 'px'); }); 不需要插件。 非常适合愚人节。我希望你在4月2日取下那个按钮!呵呵。。。这就是我们的目的:另
$('button').hover(function()
{
$(this).css('top', rand(1,1000) + 'px').css('left', rand(1,1000) + 'px');
});
不需要插件。
非常适合愚人节。我希望你在4月2日取下那个按钮!呵呵。。。这就是我们的目的:另一个
<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);
});