我正在尝试使文本随机定位在屏幕上。我该怎么做?
我正在使用纺织品
斯菲德尔
<h1 class="tlt1">Go </h1>
您可以通过position:fixed
或position:absolute
来实现此目的。
$('.tlt').each(function(){
$(this).css({"left": Math.random() * window.outerWidth , "top": Math.random() * window.outerHeight}).textillate();
});
或
$('h1').each(function(){
$(this).css({"left": Math.random() * window.outerWidth , "top": Math.random() * window.outerHeight}).textillate();
});
更新的 jsfiddle
您应该将
h1 标签的 CSS 设置为 position:fixed
。然后在每个 h1 的 javascript 中,生成器将其 left
属性设置为 Math.random() * window.outerWidth
并将其top
属性设置为 Math.random() * window.outerHeight
。