简体   繁体   English

Mobile Transform Origin Property 与 Web 不一致

[英]Mobile Transform Origin Property not consistent with Web

I have an application I am developing that allows users to drop "Pins" on an SVG. These pins can be moved around the underlying SVG and the coordinates are saved in a database.我有一个正在开发的应用程序,它允许用户在 SVG 上放置“引脚”。这些引脚可以在底层 SVG 周围移动,坐标保存在数据库中。 The pins also have a "center of mass" of bottom center, I store the coordinates of the tip of the pin, not the 0,0 origin of the pin icon.图钉还有一个底部中心的“质心”,我存储图钉尖端的坐标,而不是图钉图标的 0,0 原点。

I am trying to implement a functionality, that will allow the pins to show larger when zoomed out of the underlying SVG, and scale smaller when zooming in (think google maps, if you look at a zoomed out map of all restaurants and then zoom in, the pins get smaller and more spread out).我正在尝试实现一项功能,当缩小底层 SVG 时,允许引脚显示更大,放大时缩小(想想谷歌地图,如果你查看所有餐厅的缩小 map,然后放大,引脚变得更小,更分散)。

I have this feature working on desktop web, see images below我在桌面 web 上有这个功能,见下图
在此处输入图像描述

在此处输入图像描述

However, on mobile, the same code causes the pins to exist in a different location, and when zooming I can see them scaling down to the top left point, and not the center bottom like the desktop client.然而,在移动设备上,相同的代码导致图钉存在于不同的位置,并且在缩放时我可以看到它们缩小到左上角,而不是像桌面客户端那样的中心底部。

在此处输入图像描述

在此处输入图像描述

JS Code that is creating the scaling styles and logic:创建缩放 styles 和逻辑的 JS 代码:

 if (instance) { instance.dispose(); instance = panzoom($('#partialDiv')[0]); var pins = Array.from(document.querySelectorAll('.draggable')); instance.on('transform', function(pz) { var transform = instance.getTransform(); pins.forEach(pin => { if (transform.scale > 10 && transform.scale < 18) { pin.setAttribute("transform", 'matrix(' + 15 / transform.scale + ', 0, 0, ' + 15 / transform.scale + ', ' + pin.transform.baseVal[0].matrix.e + ', ' + pin.transform.baseVal[0].matrix.f + ')'); var pinStyle = pin.style; pin.setAttribute("transform-origin", "" + pin.getBBox().width / 2 + " " + pin.getBBox().height + "0px"); pinStyle.transformBox = 'fill-box'; pin.style['-webkit-transform-origin-x'] = '50%'; pin.style['-webkit-transform-origin-y'] = 'bottom'; pinStyle.transformBox = 'fill-box'; } else if (transform.scale > 18) { pin.setAttribute("transform", 'matrix(0.8, 0, 0, 0.8, ' + pin.transform.baseVal[0].matrix.e + ', ' + pin.transform.baseVal[0].matrix.f + ')'); var pinStyle = pin.style; pin.setAttribute("transform-origin", "" + pin.getBBox().width / 2 + " " + pin.getBBox().height + "0px"); pinStyle.transformBox = 'fill-box'; pin.style['-webkit-transform-origin-x'] = '50%'; pin.style['-webkit-transform-origin-y'] = 'bottom'; } else { pin.setAttribute("transform", 'matrix(2, 0, 0, 2, ' + pin.transform.baseVal[0].matrix.e + ', ' + pin.transform.baseVal[0].matrix.f + ')'); var pinStyle = pin.style; pin.setAttribute("transform-origin", "" + pin.getBBox().width / 2 + " " + pin.getBBox().height + "0px"); pinStyle.transformBox = 'fill-box'; pin.style['-webkit-transform-origin-x'] = '50%'; pin.style['-webkit-transform-origin-y'] = 'bottom'; } }); }); }
Why would the pins be displayed at a different origin on Chrome Desktop vs. Chrome IOS? 为什么这些图钉在 Chrome 桌面和 Chrome IOS 上显示在不同的来源? Same is true for other desktop browsers and Safari on mobile. 其他桌面浏览器和移动设备上的 Safari 也是如此。 I have tried variations of webkit styles but it does not seem to change this behavior. 我已经尝试了 webkit styles 的变体,但它似乎并没有改变这种行为。 Any advice is much appreciated. 非常感谢任何建议。

After hours of troubleshooting I learned that there is a bug on IOS webkit 16.2+ that does not allow transform-origin to work with a transform attribute.经过数小时的故障排除后,我了解到 IOS webkit 16.2+ 上存在一个错误,该错误不允许 transform-origin 使用 transform 属性。 Only the transform being performed in CSS will work with a transform-origin style.只有在 CSS 中执行的转换才能使用转换源样式。

Useful resource for anyone having an issue similar to me: https://caniuse.com/mdn-svg_attributes_presentation_transform-origin对于遇到与我类似问题的任何人的有用资源: https://caniuse.com/mdn-svg_attributes_presentation_transform-origin

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

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