gpt4 book ai didi

javascript - 鼠标悬停仅在第一次触发,为什么?

转载 作者:行者123 更新时间:2023-11-30 10:16:08 24 4
gpt4 key购买 nike

我确信这相当简单,但我已经尝试了太久,所以非常感谢您的帮助。有什么想法为什么这只适用于第一次悬停

var divwidth = $('#donatebutton').width();
var divheight = $('#donatebutton').height();

var posx = (Math.random() * ($(document).width() - divwidth)).toFixed();
var posy = (Math.random() * ($(document).height() - divheight)).toFixed();

$('#donatebutton').mouseover(function(){
$(this).css({
'position':'absolute',
'left':posx+'px',
'top':posy+'px'
}).appendTo( 'body' );

});

最佳答案

更改此代码:

var divwidth = $('#donatebutton').width();
var divheight = $('#donatebutton').height();

var posx = (Math.random() * ($(document).width() - divwidth)).toFixed();
var posy = (Math.random() * ($(document).height() - divheight)).toFixed();

$('#donatebutton').mouseover(function(){
$(this).css({
'position':'absolute',
'left':posx+'px',
'top':posy+'px'
}).appendTo( 'body' );

});

到此代码

var divwidth = $('#donatebutton').width();
var divheight = $('#donatebutton').height();

$('#donatebutton').mouseover(function(){
var posx = (Math.random() * ($(document).width() - divwidth)).toFixed();
var posy = (Math.random() * ($(document).height() - divheight)).toFixed();
$(this).css({
'position':'absolute',
'left':posx+'px',
'top':posy+'px'
}).appendTo( 'body' );

});

这将改变鼠标悬停时的随机值

关于javascript - 鼠标悬停仅在第一次触发,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23625411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com