小编enx*_*eta的帖子

箭头不显示在 svg 中

我有以下 svg,带有箭头。由于某种原因,它没有出现在 Firefox 中。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg5"
   inkscape:version="1.1 (1:1.1+202105261517+ce6663b3b7)"
   sodipodi:docname="test.svg"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <sodipodi:namedview
     id="namedview7"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageshadow="2"
     inkscape:pageopacity="0.0"
     inkscape:pagecheckerboard="0"
     inkscape:document-units="mm"
     showgrid="false"
     inkscape:zoom="0.92648709"
     inkscape:cx="382.08843"
     inkscape:cy="460.88068"
     inkscape:window-width="1920"
     inkscape:window-height="1143"
     inkscape:window-x="0"
     inkscape:window-y="0"
     inkscape:window-maximized="1"
     inkscape:current-layer="layer1" />
  <defs
     id="defs2">
    <marker
       style="overflow:visible;"
       id="Arrow2Lend"
       refX="0.0"
       refY="0.0"
       orient="auto"
       inkscape:stockid="Arrow2Lend"
       inkscape:isstock="true">
      <path
         transform="scale(1.1) rotate(180) translate(1,0)"
         d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
         style="fill-rule:evenodd;fill:context-stroke;stroke-width:0.62500000;stroke-linejoin:round;"
         id="path899" />
    </marker> …
Run Code Online (Sandbox Code Playgroud)

svg

9
推荐指数
1
解决办法
1166
查看次数

SVG animateTransform 平移和缩放同时失败

我有一条路径,我想使用 来制作动画animateTransform。我想同时平移和缩放路径。这不起作用。显然只有第二个动画在工作:在这种情况下scale。我究竟做错了什么?

svg{
width:300px; 
border:1px solid;
fill:none;
stroke:black;
}
Run Code Online (Sandbox Code Playgroud)
<svg viewBox="-100 -100 200 200">

<path d="M-36.911,0C-36.911,-19.833,-19.833,-35.911,0,-35.911C19.833,-35.911,35.911,-19.833,35.911,0C35.911,19.833,19.833,35.911,0,35.911C-19.833,35.911,-36.911,19.833,-36.911,0z">

     <animateTransform
      attributeType="xml" 
      attributeName="transform"
      type="translate"
      dur="5s"
      values="0,0; 0,-50; 0,0; 0,50;0,0"
      repeatCount="indefinite"/>
   <animateTransform 
     attributeType="xml" 
     attributeName="transform" 
     type="scale"
     dur='5s'
     values="1;1.2;1;1.2;1"
     repeatCount="indefinite"/>
            
  </path>
  
  <circle r="1" />
</svg>
Run Code Online (Sandbox Code Playgroud)

svg smil

8
推荐指数
1
解决办法
4304
查看次数

调整 svg 组路径的大小

我想将路径大小调整为 20 像素左右。

SVG 的尺寸应为 500 * 500,现在路径宽度为 297,高度为 180.7。现在我需要在前一条路径内这条宽度为 277、高度为 160.7 的路径。

<!DOCTYPE html>
<html>
<body>

<h1>Scale Paht Svg`**`enter code here`**`</h1>

<svg width="500" height="500">
    <path xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#000000" d="M245.5,263.5l-148,179c0,0,287,4,297,0L245.5,263.5z"/>
</svg> 
Run Code Online (Sandbox Code Playgroud)

svg

4
推荐指数
1
解决办法
9671
查看次数

如何在 JavaScript 中以编程方式在画布上绘制三角形?

我正在尝试在画布上创建一个三角形。但我不确定哪一边是 x1、y1、x2、y2 ... 等。我将我的三角形与该网站上给出的三角形相匹配。但我看到了不同的结果。这是我的JSFiddle

\n\n

这是我的代码:

\n\n

\r\n
\r\n
    var canvasElement = document.querySelector("#canvas");\r\n    var ctx = canvasElement.getContext("2d");\r\n\r\n    // Sides: a = 30 \xe2\x80\x83 b = 30 \xe2\x80\x83 c = 59\r\n\r\n    var triangle = {\r\n        x1: 30, \r\n        y1: 0, \r\n        x2: 0, \r\n        y2: 59, \r\n        x3: 30, \r\n        y3: 59 \r\n    }\r\n\r\n    ctx.strokeStyle = \'red\';\r\n    \r\n    ctx.beginPath();\r\n    ctx.moveTo(triangle.x1, triangle.y1);\r\n    ctx.lineTo(triangle.x2, triangle.y2);\r\n    ctx.lineTo(triangle.x3, triangle.y3);\r\n    ctx.lineTo(triangle.x1, triangle.y1);\r\n    ctx.closePath();\r\n    ctx.stroke();
Run Code Online (Sandbox Code Playgroud)\r\n
<canvas id="canvas" width="300" height="300"></canvas>\r\n    
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

javascript canvas shapes

3
推荐指数
1
解决办法
8785
查看次数

在滤镜内制作 feDropShadow 动画

我有以下代码,我想feDropShadow在里面制作动画defs

@import url("https://fonts.googleapis.com/css?family=Open+Sans:300&display=swap");

*,
*::before,
*::after {
	box-sizing: border-box;
	position: relative;
}

html,
body {
	padding: 0;
	margin: 0;
	width: 100%;
	height: 100%;
}

body {
	display: flex;
	justify-content: center;
	align-items: center;
	font-family: "Open Sans", sans-serif;
}

:root {
	--easing: cubic-bezier(0.87, 0.08, 0.23, 0.91);
	--duration: 0.3s;
	--pink: #770946;
}

#app {
	height: 100vh;
	width: 100%;
	background: #1e0238;
	position: relative;
	overflow: hidden;
}

.circle-pink {
	transform: scale(1);
	fill: none;
	stroke: var(--pink);
	stroke-width: 6;
}

.circle-fill {
	transform: scale(1); …
Run Code Online (Sandbox Code Playgroud)

html svg svg-animate svg-filters

3
推荐指数
1
解决办法
483
查看次数

svg 作为背景图像,带有遮罩来更改颜色,并带有阴影来显示阴影

我是 html 和 css 编码的初学者,所以有一个关于 svg 的问题。当我使用 svg 作为背景图像并想要更改颜色并给出阴影时,它不能同时使用这两个属性。希望可以有人帮帮我:

    .image-container {
        width: 100px;
        height: 100px;
        background-size: 100%;
        background-color: #E1A95F;
        -webkit-mask-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/18515/heart.svg");
        -webkit-mask-size: cover;
        filter: drop-shadow(1px 1px 4px rgba(0,0,0,0.75));
    }
Run Code Online (Sandbox Code Playgroud)
   <div class="image-container"></div>
    


 
Run Code Online (Sandbox Code Playgroud)

css svg css-filters css-mask

3
推荐指数
1
解决办法
4187
查看次数

沿 SVG 中的路径定位对象

我在 SVG 中有一个椭圆。

<ellipse cx="960" cy="600" rx="700" ry="480"/>
Run Code Online (Sandbox Code Playgroud)

<path>如果需要,可以在 a 中绘制相同的形状。

是否可以沿着这条路径精确定位一个对象(例如一个圆),路径的角度或百分比?

svg

2
推荐指数
1
解决办法
633
查看次数

线条按钮动画

当悬停在按钮上时,我需要制作动画线,从顶线的中间开始,线应该朝不同的方向移动并改变颜色。关于应该像这样工作,但是,它从顶部中间开始:

代码笔

 <section class="hero">
      <div class="svg-container">
         <a class="magic-link" href="#">
            <svg class="gradient" height="60" width="320" xmlns="http://www.w3.org/2000/svg">
              <defs>
                <linearGradient id="gradient">
                  <stop offset="0%" stop-color="#EB3349" />
                  <stop offset="95%" stop-color="#EB3349" />
                </linearGradient>
              </defs>
              <rect class="rect-shape" height="60" width="320" />
              <div class="text">Hover me</div>
            </svg>
         </a>
      </div>
    </section>
Run Code Online (Sandbox Code Playgroud)

javascript css jquery svg

1
推荐指数
1
解决办法
204
查看次数

在JavaScript中获取数组的深度

为了获得数组的深度,我想我可以使用如下flat()方法:

function getArrayDepth(ry){
  // number of levels: how deep is the array
  let levels = 1;
  // previous length
  let prev_length = 1;
  // current length
  let curr_length = ry.length;
  //if the resulting array is longer than the previous one  add a new level
  while(curr_length > prev_length){
  ry = ry.flat();
  prev_length = curr_length
  curr_length = ry.length;
  levels ++
  }
  return levels;
}



let testRy = [1,2,[3,4,[5,6],7,[8,[9,91]],10],11,12]

console.log(testRy);

console.log(getArrayDepth(testRy))

console.log(testRy);
Run Code Online (Sandbox Code Playgroud)

如果其中一个数组的长度为1,它将接缝工作,但

让testRy = [1,2,3,4,[5,6],7,[8,[9] ],10],11,12]

该函数失败,因为展平的数组与前一个数组一样长。

有没有更好的方法来获取JavaScript中数组的深度?

javascript arrays

1
推荐指数
3
解决办法
1178
查看次数