HTML5 simulated flashlight lighting effect
A very realistic HTML5 simulated flashlight lighting effect. HTML5 SVG realizes the special effect of lighting the flashlight on the ground, and the light follows the movement of the mouse pointer.
<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>
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
24 Jun 2016
61 web page special effects that are very fashionable and have great visual effects
24 Jun 2016
Animation loading special effects implemented in pure css3
06 Jul 2016
jquery waterfall flow LightBox picture box special effects
24 Jun 2016
A batch of hover special effects implemented by CSS3
24 Jun 2016
Revealing the special effects in Tencent’s Burberry event page
06 Jul 2016
CSS3 mouse slides over animated line border special effects
24 Jun 2016
Based on css3 cool page loading animation special effects code
Hot Tools
HTML5 Canvas heart fluttering animation special effects
HTML5 Canvas heart fluttering animation special effect is a generated animation that can be directly opened with a browser to see a heart.
H5 panda bouncing game source code
HTML5 Mobile Panda is also a crazy game source code. Game description: Press and hold the screen to adjust the strength of the panda spring and jump to the stone pillar. The game ends if you fall into the river.
HTML5 Valentine's Day box animation special effects
Based on svg, draw animations of opening love box gifts on Valentine's Day, and special effects of love box animation.
H5 3D rolling ball game source code
HTML5 cool 3D ball rolling mobile game code download. Game introduction: A colored ball rolls, and the current track of the colored ball is controlled by dragging it with the mouse or the touch screen of the mobile phone. This is a simple and easy-to-operate mobile game source code.