我正在尝试实现与此类似的功能(http://www.radimpesko.com/fonts/larish-alte),即图片(鸟)随机出现在html页面上,您必须等待片刻,才能让“鸟”开始填充页面。你知道该怎么做吗?
我读到它可能需要在网格上映射对象。因此,任何帮助都是非常感谢的。谢谢。
发布于 2015-03-13 00:00:32
像这样的东西可能行得通。
var Bird = function() {
var image = "/image/to/bird.png";
var position = {
top : Math.floor(Math.random() * 100) + 1),
left : Math.floor(Math.random() * 100) + 1)
}
var width = 20;
var height = 20;
var make = function() {
return '<div style="top:' + top + '%;left:' + left + '%;position:absolute;background-image:url(' + image + ');width:' + width + 'px;height:' + height + 'px;"></div>';
}
return make();
}
(function makeBird() {
setTimeout(function() {
var bird = new Bird();
$('body').append(bird);
makeBird();
}, 1000);
});警告:这是未经测试的,您可能应该考虑冲突并处理它们
https://stackoverflow.com/questions/29013069
复制相似问题