<div>
  feSpecularLighting.lighting-color =
  <input id="lightingColor" type="color" value="#476CC2" oninput="onColorChange(arguments[0])" />
</div>
<div>
  feSpecularLighting.surfaceScale =
  <input id="surfaceScale" type="number" step="1" value="1" oninput="onSurfaceScaleChange(arguments[0])" />
</div>
<div>
  feSpecularLighting.specularConstant =
  <input id="specularConstant" type="number" step="0.1" value="1" min="0" oninput="onSpecularConstantChange(arguments[0])" />
</div>
<div>
  feSpecularLighting.specularExponent =
  <input id="specularExponent" type="number" step="0.1" value="1" min="0" oninput="onSpecularExponentChange(arguments[0])" />
</div>
<br>
<div>
  fePointLight.z =
  <input id="fePointLightZ" type="number" step="1" value="50" oninput="onZChange(arguments[0])" />
</div>
<br>

<svg width="400" height="200" xmlns="http://www.w3.org/2000/svg" onmousemove="onMouseMove(arguments[0])">

  <!-- No light is applied -->
  <text text-anchor="middle" x="100" y="20">No Light</text>
  <circle id="myCircle" cx="100" cy="120" r="50" fill="green" />

  <filter id="filterLight">
    <feSpecularLighting id="feSpecularLighting" lighting-color="#476CC2" surfaceScale="1" result="specOut">
      <fePointLight id="myPointLight" x="50" y="70" z="50" />
    </feSpecularLighting>
  </filter>
  <g transform="translate(200)">
    <text text-anchor="middle" x="100" y="20">fePointLight 点光源</text>
    <use href="#myCircle" filter="url(#filterLight)" />
  </g>
  <circle id="myPoint" cx="250" cy="70" r="5" fill="red" />
  <line id="myLine" x1="250" y1="70" x2="300" y2="120" stroke="red" />
</svg>
function onColorChange(e) {
  const feSpecularLighting = document.getElementById("feSpecularLighting");
  feSpecularLighting.setAttribute("lighting-color", e.target.value);
}
function onSurfaceScaleChange(e) {
  const feSpecularLighting = document.getElementById("feSpecularLighting");
  feSpecularLighting.setAttribute("surfaceScale", e.target.value);
}
function onSpecularConstantChange(e) {
  const feSpecularLighting = document.getElementById("feSpecularLighting");
  feSpecularLighting.setAttribute("specularConstant", e.target.value);
}
function onSpecularExponentChange(e) {
  const feSpecularLighting = document.getElementById("feSpecularLighting");
  feSpecularLighting.setAttribute("specularExponent", e.target.value);
}
function onZChange(e) {
  const myPointLight = document.getElementById("myPointLight");
  myPointLight.setAttribute("z", e.target.value);
}

function onMouseMove(e) {
  console.log(e)
  const myPoint = document.getElementById("myPoint");
  myPoint.setAttribute("cx", e.offsetX);
  myPoint.setAttribute("cy", e.offsetY);
  const myLine = document.getElementById("myLine");
  myLine.setAttribute("x1", e.offsetX);
  myLine.setAttribute("y1", e.offsetY);

  const myPointLight = document.getElementById("myPointLight");
  // 因为 g.transform="translate(200)",所以这里需要减去 200
  myPointLight.setAttribute("x", e.offsetX - 200);
  myPointLight.setAttribute("y", e.offsetY);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.