仅当该小部件托管在某个页面上时,我才一直在以HTML / SVG javascript驱动的小部件中的IE(包括IE11在内的所有版本)上的不良性能上遇到很多麻烦。
确定减速的主要原因是重新绘制Paint / Render层和exhausting the information about these I could get out of IE Developer Tools之后,我尝试反复尝试一次关闭祖先类,直到性能得到提高;然后,在识别类时,一次关闭一个样式规则。
我的整个问题似乎都归结为在距离树数div的祖先上的一个overflow: hidden;规则。
它产生的差异是令人难以置信的:通过在树上添加overflow: hidden;,简单的用户交互(突出显示SVG路径,生成HTML文本标签,显示标签并将其相对于SVG路径和容器定位)最大程度地提高了处理器的性能,减少了UI帧速率为零,并在每次互动时冻结所有死点,持续时间在1,000到4,000毫秒之间。在祖先上没有overflow: hidden;的情况下,它会在数十毫秒内完成,并且帧速率永远不会降到一半以下(无论overflow: hidden;为何,非IE浏览器都是相同的)。
overflow: hidden;,分析了交互作用和交互作用,并过滤了绘制事件:
overflow: hidden;的配置文件,分析了交互作用和交互作用,并进行了过滤以绘制事件。唯一的变化是在DOM检查器中勾选或取消勾选overflow: hidden;样式旁边的复选框,并且按什么顺序进行测试都没有关系:
overflow: hidden;当作一个粘贴膏药而说完成了工作,不了解这种情况是如何发生的,并且冒着其他看似微不足道的CSS更改再次发生该问题的风险。我更希望了解overflow: hidden;为什么如此重要,并以健壮的方式解决了这一问题,无论应用了什么溢出规则,它都可以工作。 <div class="responsive-grid">
<!-- ...lots of nested divs that simply inherit styles, I can't change this aspect of the Drupal layout -->
<div id="panel-5" class="col-12"> <!-- width: 100%; float: left -->
<!-- this is the first element IE looks at for offsetWidth when doing the changes below -->
<!-- ...a few more nested divs without layout-changing styles -->
<div class="panel"> <!-- overflow: hidden; clear: both; border: 1px; -->
<!-- this is the element where removing the overflow: hidden changes everything -->
<!-- I'm not sure what clear:both is for here, since no siblings. Seems redundant -->
<!-- ...a few more nested divs with no style rules, some contain <p>s <h2>s etc... -->
<div class="container"> <!-- position: relative; -->
<div class="sub-column col-8"> <!-- width: 66%; display: inline-block -->
<div class="square"> <!-- width: 100%; padding-bottom: 100%; position: relative -->
<svg viewbox="0 0 500 500" preserveAspectRatio="XMinYMin meet" ...>
<!-- svg position: absolute; width:100%; height: 100% -->
Many paths here
<div class="label"> <!-- fixed width in pixels; position: absolute -->
Some text here
</div>
</div>
</div>
<div class="sub-column col-4"> <!-- width: 33%; display: inline-block -->
<div class="sidebar">
Many interactive controls here
<!-- .square, svg andd .sidebar contain the only elements that are updated -->
</div>
</div>
</div>
<!-- some more ordinary position: static text containers -->
</div>
</div>
</div>
overflow: hidden;的情况下,有什么方法可以防止它发生?overflow: hidden;实际上并未在此页面上剪切太多(如果有的话)(但是我不能仅仅删除它,因为它是模板的一部分,会影响数百个其他页面,但确实有影响)。overflow: hidden;和border-radius(在我的情况下为3px)时,才会出现该问题。有了一个但没有另一个,问题就消失了。overflow: hidden;而不是border-radius的示例。也许比上述速度慢一点,但是区别很小:
overflow: hidden;和border-radius的示例:
最佳答案
经过大量测试之后,我想我开始了解这里发生的情况。不过,这纯粹是基于观察,因此,如果有人有一个答案,我仍然渴望有一个更权威的答案。
是什么原因造成的?
似乎只有在所有这些都成立的情况下才会发生:
overflow: hidden和border-radius(或-ms-border-radius)。在我的测试中,如果同一分支中的不同祖先具有这些样式,则不会发生。 position: absolute;或position: relative; position: absolute; / relative影响的元素数量及其复杂性相比,该问题似乎也更加明显。例如,在固定比例的宽高比为SVG的比例缩放百分比宽度SVG容器中有SVG路径的情况下,此问题非常明显;如果给此分支指定了position: static,但另一个分支的divs宽度为%-div,且其祖先为position: absolute;,则与删除overflow: hidden;或border-radius中的一个相比,该问题仍然可观察到,但严重性要小得多。offsetWidth计算一直到路径,即made no sense to me and prompted a related question,因为SVG容器中的路径肯定不会影响容器外部的布局。overflow: hidden;并得出结论,它可以通过在对它们进行重绘/重排/绘制等事件之前识别出完全超出元素范围的元素来提高性能。 position: absolute;和position: relative;,并得出结论,这些及其子项可能完全位于容器之外,并且像border-radius,这种情况仍然会发生,但是在这种情况下,它是微不足道的,并且会花费数毫秒的时间。 overflow: hidden元素的形状不是矩形,因此需要更复杂的计算才能确定overflow: hidden或border-radius移到一个子元素,这样它们就不会同时位于同一元素上。任务完成。border-radius样式对于美学而言不是必需的,并且overflow: hidden;可能对于结构而言是必不可少的,因此,如果浏览器是IE,则查找祖先树并从任何内容中删除border-radius同时具有overflow: hidden;的元素。if( isAnyIE() ) {
$container.parentsUntil("body").filter(function(){
var $this = $(this),
overflow = $this.css('overflow');
return ( overflow === 'hidden' && hasBorderRadius( $this ) );
}).addClass( 'remove-border-radius' );
}
function hasBorderRadius( $element ){
function getNum( style ){
return parseFloat( $element.css( 'border-'+style+'-radius' ) ) || 0;
}
var number = 0;
number += getNum( 'top-left' );
number += getNum( 'bottom-left' );
number += getNum( 'top-right' );
number += getNum( 'bottom-right' );
$element = null;
return !!number;
}
function isAnyIE(){
// isIE(): use conditional comments and classes, see https://stackoverflow.com/a/18615772/568458
// isIE10: use user agent like navigator.appVersion.indexOf("MSIE 10") !== -1;
// isIE11: use user agent like !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
return isIE11() || isIE10() || isIE();
}
.remove-border-radius {
border-radius: 0 0 0 0 !important;
-ms-border-radius: 0 0 0 0 !important;
}
关于javascript - 如何溢出:隐藏;和容器上的border-radius会导致容器内 “Paint/Render Layer”的大量减速,仅在IE上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39490557/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我有一大串格式化数据(例如JSON),我想使用Psychinruby同时保留格式转储到YAML。基本上,我希望JSON使用literalstyle出现在YAML中:---json:|{"page":1,"results":["item","another"],"total_pages":0}但是,当我使用YAML.dump时,它不使用文字样式。我得到这样的东西:---json:!"{\n\"page\":1,\n\"results\":[\n\"item\",\"another\"\n],\n\"total_pages\":0\n}\n"我如何告诉Psych以想要的样式转储标量?解