尝试在页面周围随机移动我的div。目前新的随机生成的div出现在页面上的新位置,而不是转换到新位置(我希望div跨页面跟踪而不是删除自身并重新出现)。
char folderpath[256];
printf("enter the path : \n");
scanf("%s",folderpath);
...
d = opendir(folderpath);

function randomdiv1 () {
var divnum = $('.random').length;
var random = $('.random');
var startleft =random.css('left', (Math.floor(Math.random() * ($(window).width()-50))));
var starttop =random.css('top', (Math.floor(Math.random() * ($(window).height()-50))));
return [startleft, starttop];
}
function randomdiv2 () {
var divnum = $('.random').length;
var random = $('.random');
var endleft =random.css('left', (Math.floor(Math.random() * ($(window).width()-50))));
var endtop =random.css('top', (Math.floor(Math.random() * ($(window).height()-50))));
return [endleft, endtop];
}
function randomdiv3 () {
var startdiv = randomdiv1 ();
var enddiv = randomdiv2 ();
$('.random').animate({
top: enddiv[1],
left: enddiv[0],
}, 2000, 'swing', randomdiv3);
}
randomdiv3 ();

.random {
width: 50px;
height: 50px;
background-color: blue;
position: absolute;
}

答案 0 :(得分:1)
这可以通过将以下css属性添加到.random
:
transition: left 2s, top 2s;
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
以下示例: