[英]Does the number of popovers affect page load speed?
I have a page with possibly 2000 popovers using bootstrap 4. 我有一个页面,使用引导程序4可能有2000个弹出窗口。
Does the number of popovers affect the page speed? 弹出窗口的数量是否会影响页面速度? I don't know enough about javascript frameworks to understand whether loading 10 popovers has the same effect as loading 2000. That is what I want to understand.
我对javascript框架了解不足,无法了解加载10个弹出窗口是否与加载2000年具有相同的效果。这就是我想了解的内容。
The contents of the popovers is loaded by javascript. 弹出窗口的内容由javascript加载。
One method I have used to minimize the impact of things like this is to use a single popover/modal/dialog/etc.. and then changed it's contents right before it is shown. 我用来最小化此类影响的一种方法是使用单个popover / modal / dialog / etc ..,然后在显示之前立即更改其内容。 This way you don't have 2k extra elements in the DOM that 99% of the time are doing nothing.
这样,您就不会在DOM中有2k多余的元素,而有99%的时间什么也不做。
I worked up an example of bootstrap popover's using the selector
option and delegation by enabling it on a parent element. 我使用了
selector
选项并通过在父元素上启用它来创建了一个自举弹出窗口的示例。 It appears that they may have any overhead issues worked out. 看来他们可能解决了所有开销问题。
If you inspect the body of the example, you will see a single popover div appended to the body when it is shown and then removed when it hidden. 如果检查示例的主体,则将在显示时在主体上看到一个弹出框div,然后在隐藏时将其删除。
$(function() { var $table = $('#test'); for(var i = 0; i < 20; i++) { var row = $('<tr />'); for(var j = 0; j < 100; j++) { var td = $('<td />').attr({id: (i * 100) + j, tabindex: -1}); row.append(td); } $table.append(row); } $table.popover({ html: true, container: 'body', trigger: 'focus', selector: 'td', content: function() { return '<p>This is my id: ' + $(this).attr('id') + '</p>'; } }); });
td { height: 25px; width: 25px; border: 1px solid black; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <table id="test"> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.