- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
所以,这个问题以前出现过,就像这里:Translate + Canvas = Blurry Text在这里:Is it possible to "snap to pixel" after a CSS translate?
这些链接或我读过的任何其他文章似乎都没有任何结论。一些响应者认为它不够重要,不需要关心,所以这就是为什么在我的情况下它是: Chrome 41.0.2272.104 中的屏幕截图
Safari 8.0.4 (10600.4.10.7) 中的屏幕截图
在 Safari 中详细查看损失? (看看航天飞机图像中的结构,或第三张图像中岩石的细节)
这些家伙的 CSS 是
width: 100%;
height: auto;
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
因此,在某些情况下——translateY 将以半像素结束。左边的第一张图片以这样的变换矩阵结束:
-webkit-transform: matrix(1, 0, 0, 1, 0, -56.5);
目前,chrome 似乎可以很好地呈现这个问题(我看到一些人说不同的浏览器在不同的版本中会产生这个问题),但目前 Safari 有这个问题。因此,我解决此问题的假设是确保只有完整的像素,我已经通过计算并在 javascript 中应用转换来完成,但是在运行大量图像时这会花费更多的性能时间.
我尝试了一些纯 CSS 的 hack,比如使用 scale3d,但没有成功。如果有人有任何无 JS 的解决方案,我将非常感谢分享知识。
最佳答案
在某些浏览器中,您可以利用 calc 中的浮点舍入误差将您的数字舍入到所需的最接近的增量:
calc((2.55px * 5e-324) / 5e-324)
应使 2.55 像素四舍五入为 3 像素。支持的浏览器有Chrome(包括Brave、Electron、Edge、Opera等衍生产品),不支持的浏览器有IE、Firefox、Safari(包括Midori等衍生产品)。值得庆幸的是,不支持的浏览器 IE、Firefox 和 Safari 只是将 calc 视为无效的属性值,因为使用的数字超出了可接受的范围。因此,要利用它,只需使用下面的示例来生成满足您需要的 CSS。是的,我知道这个生成器并不总是组合相似项,是的,这是有原因的:组合这些相似项会产生无法存储的数字。
var unit = document.getElementById('unit'),
precision = document.getElementById('precision'),
property = document.getElementById('prop'),
output = document.getElementById('output');
function formatProp(x) {
return (property.value.indexOf('%s') ?
property.value.replace(/%s/g, x) :
proprty.value + x).replace(/\\n/g, '\n')
.replace(/\\t/g, '\t').replace(/\\r/g, '\r');
}
(unit.oninput = precision.oninput = property.oninput = function() {
var Val = parseFloat(precision.value),
V1 = "5e-324",
V2 = "5e-324";
if (Val < 1)
V1 = V2 = '' + 5e-324 / Val;
else if (Val > 1)
V2 += ' * ' + Val, V1 += ' / ' + Val;
output.textContent = formatProp(unit.value) + '; /* for IE and FF*/\n' + formatProp('calc((' + unit.value + ' * ' + V1 + ') / ' + V2 + ')') + ';';
})();
CSS Unit: <input type="text" id="unit" value="-50%" style="width:14em" /><br /> Property : <input type="text" id="prop" value="-webkit-transform: translateY(%s);\ntransform: translateY(%s)" style="width:40em" /><br /> Round to: <input type="number" id="precision"
value="1" style="width:14em" /> pixels (can be decimal)<b5 />
<pre id="output" style="background:#eee"> </pre>
请注意,根据实时响应的语言定义,是的,您可以在上面的演示中输入您自己的值,是的,将实时生成相应的 CSS。
我创建的测试页面:purposeful-rounding-errors browser support test
请注意,虽然上面的图表目前支持浏览器,但它很可能会发生变化,因为使用舍入误差有点不标准:W3C 规范仅在 float 的定义中暗示它们,但确实从未明确声明浏览器需要实现次正规浮点符号或舍入错误。
关于css - 变换时舍入 CSS 子像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29266447/
我有这个 html 代码: HELLO WORLD! X V HELLO WORLD! X V 我想按 X(类关闭)将父 div 的高度更改为 20px 并显示 V(类打开),但在每个 d
在会计应用程序的许多不同实现中,有两种主要的数据库设计方法来保存日志和分类帐数据。 只保留 Journal 信息,然后 Ledger 只是 Journal 的一个 View (因为 journal 总
我想在另一个子里面有一个子, sub a { sub b { } } 我想为每次调用 sub b 创建一个新的 sub a 实例。有没有办法在 Perl 中做到这一点? 当我运行上面的
我有一些代码正在查找重复项并突出显示单元格: Private Sub cmdDups_Click() Dim Rng As Range Dim cel As Range Set Rng = ThisW
可能有一个简单的解决方案,但我很难过。 我有一个包含一个 ID 字段的主表。在两个可能的字段中有一个具有该 ID 的子表。想象一个由选手 A 和选手 B 组成的 double 队。Master 表将有
假设我有一个包含对象的数组: [ { "id": "5a97e047f826a0111b754beb", "name": "Hogwarts", "parentId": "
我正在尝试对 MySQL 数据库表执行一对父/子模型的批量插入,但似乎无法使用标准的 ActiveRecord 功能来完成。所以,我尝试了 activerecord-import gem,但它也不支持
我有一个带有多个子类的父抽象类。最终,我希望通过 GUI 中的进度条显示子类中完成的进度。 我目前所做的,我意识到这是行不通的,是在父类中声明为每个子类将覆盖的虚拟方法的事件方法定义。所以像: pub
是否可以通过键数组在对象中设置变量?例如我有这个对象: var obj = {'outer': {'inner': 'value'} }; 并希望设置由键数组选择的值: var keys = ['ou
我有一个名为 companies 的 MySQL 表,如下所示: +---------+-----------+-----------+ | id_comp | comp_name | id_pare
我正在尝试使用 sublime text 在 sublime text 上的 ionic 上打开我的第一个应用程序。它给了我一个“找不到命令”的错误。如何修复? 我试过这些命令: sudo rm -r
不好意思问,但我正在使用 webapp2,我正在设计一个解决方案,以便更容易定义路由 based on this google webapp2 route function .但这完全取决于能够在子级
我有代表树的数字字符串(我不知道是否有官方名称): 012323301212 上面的例子代表了 2 棵树。根用 0 表示。根的直接子代为“1”,“1”的直接子代为“2”,依此类推。我需要将它们分组到由
是否可以在当前 Activity 之上添加 Activity 。例如,假设我单击一个按钮,然后它将第二个 Activity 添加到当前 Activity 。而第二个 Activity 只覆盖了我当前
我很难思考如何为子资源建模。 以作者的书籍为例。你可以有 N 本书,每本书只有一位作者。 /books GET /books POST /books/id PUT /books/id DELETE 到
有人可以向我解释以下内容(python 2.7) 来自已解析文件的两个字符串数字: '410.9''410.9 '(注意尾随空格) A_LIST = ['410.9 '] '410.9' in '41
背景 在 PowerShell 中构建 hash table 是很常见的通过特定属性快速访问对象,例如以 LastName 为基础建立索引: $List = ConvertFrom-Csv @' I
我真的很难弄清楚如何调用嵌套 Polymer Web 组件的函数。 这是标记: rise-distribution组件有 canPlay我想从 rise-playlist
我写了一个小工具转储(以 dot 格式)一个项目的依赖关系图,其中所有位于同一目录中的文件都聚集在一个集群中。当我尝试生成包含相应图形的 pdf 时,dot开始哭: 命令 dot -Tpdf trim
给定一个 CODE ref,是否可以: 访问该 CODE ref 的解析树 通过指定 CODE ref 的解析树来创建一个新的 CODE ref,该解析树可以包含在 1 中返回的解析树的元素 通常我们
我是一名优秀的程序员,十分优秀!