简体   繁体   English

什么更快? 画一条线还是创建一个div?

[英]What is faster; drawing a line or creating a div?

I'm working with Javascript/jQuery and I'm trying to figure out what is more advantageous.我正在使用 Javascript/jQuery,我正在尝试找出什么更有利。 I want to draw a single line which will be dynamically, according to events, changing its own height, it will have just 1px width and it will be flashing on the site.我想画一条线,它会根据事件动态地改变它自己的高度,它只有 1px 的宽度,它会在网站上闪烁。 Should I create just ordinary div with width of 1px or draw a line with some javascript library function?我应该只创建宽度为 1px 的普通 div 还是用一些 javascript 库函数画一条线?

I would just use a div as you know it is cross browser/mobile browser compatible.我只想使用一个div因为你知道它是跨浏览器/移动浏览器兼容的。 If you use some sort of javascript library function, then you might find that it doesnt work in certain browsers/browser updates.如果您使用某种 javascript 库函数,那么您可能会发现它在某些浏览器/浏览器更新中不起作用。

Also it gives you the advantage of styling with css which again is cross browser compatible.它还为您提供了使用 css 进行样式设置的优势,这又是跨浏览器兼容的。

Using a native element will always be faster than implementing a custom version on your own.使用原生元素总是比自己实现自定义版本更快。 Elements are created by the browser's own executable code while anything you create will be done through its interpreter.元素由浏览器自己的可执行代码创建,而您创建的任何内容都将通过其解释器完成。

HTML/CSS 绝对更快,尽管您可能无法使用它实现您想要的效果。

If u use canvas or some svg library to draw line , then it will be much cross browser compatible..如果你使用画布或一些 svg 库来画线,那么它将会是很多跨浏览器兼容的..

Also it will take much more processing ...它还需要更多的处理......

So it would be better to use div for this purpose ...因此,为此目的使用 div 会更好......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM