Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 消失的变换_Javascript_Jquery_Html_Css_Phantomjs - Fatal编程技术网

Javascript 消失的变换

Javascript 消失的变换,javascript,jquery,html,css,phantomjs,Javascript,Jquery,Html,Css,Phantomjs,我遇到了一个奇怪的问题,phantomJS在某种程度上丢失了应用于某些图像的转换。我有一个网页,在该网页中,我有一个函数,可以获取一些html并将其粘贴到页面中。它看起来像这样: function RenderRaw(html, id) { elem = $("#raw"); elem.html(html); } <img id="map_layer0_tile_5_1_1" class="layerTile" style="width: 256px; height:

我遇到了一个奇怪的问题,phantomJS在某种程度上丢失了应用于某些图像的转换。我有一个网页,在该网页中,我有一个函数,可以获取一些html并将其粘贴到页面中。它看起来像这样:

function RenderRaw(html, id) {
    elem = $("#raw");
    elem.html(html);
}
<img id="map_layer0_tile_5_1_1" class="layerTile" style="width: 256px;
 height: 256px; visibility: visible; transform: translate(89px, -13px);" src="tile/5/11/5">
现在,在我传递的html中,我有一些图像看起来像这样:

function RenderRaw(html, id) {
    elem = $("#raw");
    elem.html(html);
}
<img id="map_layer0_tile_5_1_1" class="layerTile" style="width: 256px;
 height: 256px; visibility: visible; transform: translate(89px, -13px);" src="tile/5/11/5">
我看到的正是我所期望的,尤其是我看到的

translate(89px, -13px)
在这里,我得到了
style
transform
属性和
off.top
off.left
就是我所期望的

然而,当我通过phantomJS运行这个时,似乎
转换
被剥离了。
outerHTML
看起来与以前完全一样,但是我的行访问
style.transform
返回:

undefined
并不是说
style.width
style.height
仍然可以按预期访问。现在,如果不应用变换,我的图像将无法正确定位

有人知道这里会发生什么吗?我的
变换到哪里去了

编辑:


仔细观察,它看起来像是我在phantom中的
style
对象,我可以看到它没有
transform
属性,但是它有
webkitttransform
。所以我猜phantomJS不支持
transform

,所以问题是phantomJS 2.0根本不支持
transform
。不幸的是,报告中没有提到。为了解决这个问题,我在加载事件中为每个图像执行了以下操作:

var thisImg = $(e.target);
if (e.target.style.transform === undefined && e.target.style.webkitTransform !== undefined) {
    var style = thisImg.attr("style");
    style += "-webkit-transform: " + /transform:([^;]*;)/.exec(style)[1];
    thisImg.attr("style", style);
}

基本上提取
转换
并将其复制到
-webkit转换

,因此问题似乎在于phantomJS 2.0根本不支持
转换
。不幸的是,报告中没有提到。为了解决这个问题,我在加载事件中为每个图像执行了以下操作:

var thisImg = $(e.target);
if (e.target.style.transform === undefined && e.target.style.webkitTransform !== undefined) {
    var style = thisImg.attr("style");
    style += "-webkit-transform: " + /transform:([^;]*;)/.exec(style)[1];
    thisImg.attr("style", style);
}

基本上提取
转换
并将其复制到
-webkit转换

您使用的是什么PhantomJS版本?(您尝试过PhantomJS 2吗?)可能PhantomJS无法重新评估CSS(您可以自己尝试使用
document.body.style.zoom=document.body.style.zoom;
)。@ArtjomB。我正在运行2.0.0。0@ArtjomB.
document.body.style.zoom
技巧似乎无法迫使它重新评估。然而,强迫它重新评估似乎是个好主意。你使用的是什么PhantomJS版本?(您尝试过PhantomJS 2吗?)可能PhantomJS无法重新评估CSS(您可以自己尝试使用
document.body.style.zoom=document.body.style.zoom;
)。@ArtjomB。我正在运行2.0.0。0@ArtjomB.
document.body.style.zoom
技巧似乎无法迫使它重新评估。然而,强迫它重新评估似乎是个好主意。