javascript - 重复一个元素直到它覆盖整个屏幕

标签 javascript jquery html css

我想要重复一个 html/css 元素,直到它覆盖整个屏幕。

如何重复并只停在屏幕高度,而不是永远重复?

#container{
 height: 100vh;
 width: 100vw;
}
.dotts{
 background-color: yellow;
 border-radius: 50%;
 height: 20px;
 width: 20px;
}

function repeat(){
 $("#repeating").append($(".dotts:first").clone());
}

最佳答案

使用 height()

function repeat() {
  $("#repeating").append($(".dotts:first").clone());
}

let fill = Math.floor($(window).height() / $('.dotts:first').height())
for (let i = 1; i < fill; i++) {
  repeat()
}
#container {
  height: 100vh;
  width: 100vw;
}

.dotts {
  background-color: yellow;
  border-radius: 50%;
  height: 20px;
  width: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="repeating">
  <div class="dotts"></div>
</div>

关于javascript - 重复一个元素直到它覆盖整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59206905/

相关文章:

javascript - JS : Compare two tables and generate new one based on the two

javascript - 按索引而不是按 Angular/javascript 中的创建顺序删除对象

javascript - jQuery/Javascript : 2 function calls in line, 等待其他完成?

javascript - 即使我返回 json,也无法弄清楚为什么 Ajax 返回错误

javascript - 由于 FIREFOX 6.0 中的 QUICK FIND 自动启动,键盘快捷键在网站上不起作用

javascript - div “flickers” 和淡出/淡入移动

html - 在标签下输入而不更改html

javascript - jsPDF - 如何生成 A4 大小的所有页面的 PDF

javascript - 正则表达式分别匹配方括号中的文本

javascript - Div 在 Firefox 中不显示