【问题标题】:Making CSS clip rect responsive使 CSS 剪辑 rect 响应
【发布时间】: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,感谢您的提示。我做了` ` ,但无济于事。我已经更新了页面,所以你可以看到它的实际效果。

标签: jquery css clipping clip


【解决方案1】:

clip-pathinset 基本形状一起使用,而不是已弃用的clip
不要忘记-webkit 前缀。

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: -1px;
  border: 1px solid transparent;
}

section {
  margin: 1em;
  width: 50%;
  height: 50%;
  border: 1px dotted blue;
}
  
div {
  width: 100%;
  height: 100%;
  background: red;
  -webkit-clip-path: inset(50% 0 4px 1em);
  clip-path: inset(50% 0 4px 1em);
}
<section><div></div></section>

【讨论】:

    猜你喜欢
    • 2012-08-04
    • 2015-12-16
    • 2013-07-13
    • 1970-01-01
    • 2020-08-22
    • 2016-09-18
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    相关资源
    最近更新 更多