Javascript 当鼠标悬停在Javascript中时,棘手的按钮会移开?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11929687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:43:37  来源:igfitidea点击:

Tricky Button Moving Away when Mouseover in Javascript?

javascriptjqueryhtmlfrontend

提问by HP.

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.

有人可以指出我的来源或向我展示几行代码来做到这一点吗?最好使用jQuery。

回答by Gautam

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

这可能就是你要找的,http://jsfiddle.net/9CDtE/4/

HTML

HTML

<button>button</button>?

CSS

CSS

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

JS

JS

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