Javascript 鼠标器只是第一次开火,为什么?
我相信这是相当简单的,但我已经尝试了太久,所以我真的非常感谢一些帮助。有什么想法吗为什么这只在第一次悬停时有效Javascript 鼠标器只是第一次开火,为什么?,javascript,jquery,Javascript,Jquery,我相信这是相当简单的,但我已经尝试了太久,所以我真的非常感谢一些帮助。有什么想法吗为什么这只在第一次悬停时有效 var divwidth = $('#donatebutton').width(); var divheight = $('#donatebutton').height(); var posx = (Math.random() * ($(document).width() - divwidth)).toFixed(); var posy = (Math.random() * ($(d
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' );
});
这将更改鼠标上方的随机值更改此代码:
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' );
});
这将更改鼠标上方的随机值如果您提供了一个JSFIDLE
posx
和posy
在悬停之间不要更改,那就太好了。。。那么你预计会发生什么?您总是为left
和top
设置相同的值。处理程序已执行,但不会产生任何视觉效果。添加一个console.log
语句并亲自查看.try.on('mouseover')@甘尼什:那没什么区别。(脸掌)非常感谢菲利克斯。多蠢啊,谢谢。如果您提供了一个JSFIDLEposx
和posy
在悬停之间不要更改,那就太好了。。。那么你预计会发生什么?您总是为left
和top
设置相同的值。处理程序已执行,但不会产生任何视觉效果。添加一个console.log
语句并亲自查看.try.on('mouseover')@甘尼什:那没什么区别。(脸掌)非常感谢菲利克斯。太傻了,谢谢。这没有什么区别,除非同时有其他东西改变文档的维度。嗯,我一定错过了:D nvm;)这其实没有什么区别,除非同时有其他东西改变了文档的维度