jquery - Making CSS clip rect responsive -
i'm trying implement little here: http://atmapp.io/beta/
i'm clipping google maps object, fit in phone area. works great on 1920x1080 (mainly because hardcoded rect's values). how can make clip: rect
responsive?
i've tried jquery, i'm idiot, , i'm miles off:
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)'); });
edit
for wondering, how map supposed "fit":
use clip-path
inset
basic shape instead of deprecated clip
.
don't forget -webkit
prefix.
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>
Comments
Post a Comment