PHP中文网-QQ群-扫二维码

QQ群

PHP中文网-关注微信公众号-扫二维码

微信公众号

当前位置:php中文网下载站 >js特效 >html5特效 >HTML5的模拟手电筒照明效果

HTML5的模拟手电筒照明效果

2017-12-12 来源/作者:php中文网 分类:html5特效 «» 下载次数:0
HTML5的模拟手电筒照明效果
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5模拟手电筒照明效果</title>

<style>
html, body {
  height: 100%;
  margin: 0;
}
svg {
  display: block;
}
</style>

</head>
<body>

<svg width="100%" height="100%"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
>
  <filter id="light">
    <!-- blur the source image to make bump map less sharp -->
    <feGaussianBlur stdDeviation="3" result="blurred"></feGaussianBlur>
    <!-- create bump map based on alpha channel -->
    <feColorMatrix in="blurred" type="luminanceToAlpha" result="bumpMap"></feColorMatrix>
    <!-- use bump map for lighting filter -->
    <feDiffuseLighting in="bumpMap" surfaceScale="3" result="light">
      <fePointLight x="225" y="150" z="30"></fePointLight>
    </feDiffuseLighting>
    <!-- compose the lighting result with source image using multiplication -->
    <feComposite in="light" in2="SourceGraphic"
      operator="arithmetic"
      k1="1" k2="0" k3="0" k4="0">
    </feComposite>
  </filter>
  <pattern id="pattern1"
    width="450" height="300"
    patternUnits="userSpaceOnUse"
  >
    <image  xlink:href="img/codepen.jpg"
      width="450" height="300"
    ></image>
  </pattern>
  <rect width="100%" height="100%"
    fill="url(#pattern1)" filter="url(#light)"
  ></rect>
</svg>

<script>
const svgNode = document.querySelector('svg');
const fePointLightNode = svgNode.querySelector('fePointLight');
svgNode.addEventListener('mousemove', handleMove);
svgNode.addEventListener('touchmove', handleMove);
function handleMove(event) {
  fePointLightNode.setAttribute('x', event.clientX);
  fePointLightNode.setAttribute('y', event.clientY);
}
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"> 
</div>
</body>
</html>


申明:PHP中文网下载站匠心打造中国最大的免费下载站!一切资源免费,所有资源都经过检测,请放心下载!

效果预览本地下载  新手使用求助QQ群: