简体   繁体   English

使SVG图像响应引导容器

[英]Making SVG image responsive to bootstrap container

I have an svg canvas which reveals an image behind another one. 我有一个svg画布,可以显示另一幅画布后面的图像。 The problem is that I can't resize the svg to be full width. 问题是我无法将svg调整为全宽。 I can however provide a height. 但是我可以提供一个高度。 This doesn't work for responsiveness and I would like to know if it's at all possible to set a responsive width so it always shows with automatically adjusting the height. 这对于响应速度不起作用,我想知道是否有可能设置响应宽度,以便始终显示自动调整高度。

 var svgNS = "http://www.w3.org/2000/svg"; $('.pic').mousemove(function(event) { event.preventDefault(); var upX = event.clientX; var upY = event.clientY; var mask = $('#mask1')[0]; var circle = document.createElementNS(svgNS, "circle"); circle.setAttribute("cx", upX); circle.setAttribute("cy", upY); circle.setAttribute("r", "50"); circle.setAttribute("fill", "white"); circle.setAttribute("filter", "url(#filter2)"); mask.appendChild(circle); setTimeout(function() { circle.style.opacity = '0'; setTimeout(function() { mask.removeChild(circle); }, 300); }, 4000); }); 
 body { margin: 0; padding: 0; } .pic { text-align: center; position: relative; height: 400px; margin: 0; padding: 0; } .blur { height: 100%; width: 100%; } .overlay { position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; } circle { opacity: 1; -webkit-transition: opacity 200ms linear; transition: opacity 200ms linear; } 
 <div class="container-fluid"> <div class="row"> <div class="pic"> <svg class="blur" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%"> <image filter="" xlink:href="http://staging.600lines.com/alta-2-12-16/img/a.jpg" width="100%" height="100%"></image> <filter id="filter2"> <feGaussianBlur stdDeviation="10" /> </filter> <mask id="mask1"> <circle cx="-50%" cy="-50%" r="30" fill="white" filter="" /> </mask> <image xlink:href="http://staging.600lines.com/alta-2-12-16/img/b.jpg" width="100%" height="100%" mask="url(#mask1)"></image> </svg> </div> </div> </div> 

Codepen Codepen

Any help would be greatly appreciated! 任何帮助将不胜感激!

I think this may help you. 我认为这可能对您有帮助。 Remove width and height and adjust percentaje or use em units: 删除宽度高度并调整百分比或使用em单位:

.blur {
  background-size: 100%;
}

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

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