【发布时间】:2015-08-25 23:51:21
【问题描述】:
我正在尝试在这里实现一些东西:http://atmapp.io/beta/
我正在剪裁一个 Google 地图对象,以适应手机区域。它在 1920x1080 上效果很好(主要是因为我硬编码了矩形的值)。如何使clip: rect 响应?
我尝试过使用 jQuery,但我是个白痴,而且我可能还差得很远:
CSS
#map-canvas2 {
width:100%;
height: 100%;
position: absolute;
z-index: 9999;
bottom: 0;
clip:rect(191px, 1579px, 732px, 1275px);
}
jQuery
var oldresX = 1920;
var oldresY = 943;
var rectTop = 191;
var rectRight = 1579;
var rectBottom = 732;
var rectLeft = 1275;
var newRectTop;
var newRectRight;
var newRectBottom;
var newRectLeft;
var newResX;
var newResY;
$(window).resize(function(){
newResY = oldresY - window.innerHeight;
newResX = oldresX - window.innerWidth;
newRectTop = rectTop + newResY;
newRectRight = rectRight - newResX;
newRectBottom = rectBottom - newResY;
newRectLeft = rectLeft + newResX;
//alert(newResX + "x" + newResY);
$("#map-canvas2").css('clip', 'rect('+newRectTop +'px, '+newRectRight +'px, '+newRectBottom +'px, '+ newRectLeft+'px)');
//alert('rect('+newRectTop +'px, '+newRectRight +'px, '+newRectBottom +'px, '+ newRectLeft+'px)');
});
编辑
对于那些想知道的人,这就是地图应该“适合”的方式:
【问题讨论】:
-
那么问题出在哪里?该页面在我的 iPhone 上运行良好
-
要让剪辑使用响应式布局,您需要使用百分比值。但是,剪辑不支持百分比值。您可以尝试改用剪辑路径。查看species-in-pieces.com/#
-
@idmean,第二张地图没有显示在手机上。
-
@jackson,感谢您的提示。我做了` ` ,但无济于事。我已经更新了页面,所以你可以看到它的实际效果。