<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML5逼真的陨石流星动画特效</title>
<style>
body {
background-color: #1C121D;
overflow: hidden;
text-align: center;
}
body,
html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
svg {
position: absolute;
width: 100%;
height: 100%;
visibility: hidden;
transform: translate(-50%, 0%);
}
</style>
</head>
<body>
<svg viewBox="200 150 400 300" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="asteroidGrad" cx="400" cy="304.08" r="9" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#2d1e2f" stop-opacity="0" />
<stop offset="1" stop-color="#1c121d" />
</radialGradient>
<radialGradient id="asteroidGlowGrad" cx="400" cy="304.08" r="162" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#2d1e2f" stop-opacity="0" />
<stop offset="1" stop-color="#A9E5BB" stop-opacity="1" />
</radialGradient>
<linearGradient id="tailGrad" x1="400" y1="380.2" x2="400" y2="0" gradientUnits="userSpaceOnUse">
<stop class="tailColor" offset="0" stop-color="#00a9e5" stop-opacity="0.3" />
<stop class="tailGradOffset" offset="1" stop-color="#1C121D" stop-opacity="0" />
</linearGradient>
<radialGradient id="burnupGrad" cx="401.11" cy="271.93" fy="214" r="69.63" gradientTransform="translate(0 -160.37) scale(1 1.52)" gradientUnits="userSpaceOnUse">
<stop offset="0.51" stop-color="#1C121D" stop-opacity="0" />
<stop class="burnupStop" offset="0.94" stop-color="#fbb03b" stop-opacity="0.4" />
</radialGradient>
<pattern id="asteroidPattern" x="0" y="0" width="18" height="18" patternUnits="userSpaceOnUse" viewBox="0 0 18 18">
<g fill="#1C121D">
<rect width="18" height="18" fill="none" />
<path d="M11,19.88c-.34.28-1.37-.35-2-1s-1.27-1.71-1-2,2.49.47,3,2C11,19,11.26,19.67,11,19.88Z" />
<path d="M2,1.88a2.86,2.86,0,0,0,0,3c.64.72,1.57.31,2,1s-.34,1.45,0,2c.57.94,4.16,1,5-1a3.32,3.32,0,0,0-2-4c-.81-.22-1.19.32-2,0-1.19-.48-1.27-2-2-2C2.53.88,2.2,1.51,2,1.88Z" />
<path d="M11,14.88c0,.64-.09.75,0,1a1.71,1.71,0,0,0,2,1,1.84,1.84,0,0,0,1-2c-.22-1.57-2.51-2.43-3-2C10.77,13.08,11.06,13.45,11,14.88Z" />
<path d="M1,10.88c.39-.46,1.4-.29,2,0,.27.13.9.44,1,1s-.77.92-1,2c-.19.89.31,1.21,0,2,0,.08-.36.87-1,1-.89.18-2-1-2-2,0-.81.78-.91,1-2S.63,11.32,1,10.88Z" />
<path d="M15,1.88c-.1,0,.1.41,0,1-.15.87-.74,1-1,2a1.23,1.23,0,0,0,0,1,1.46,1.46,0,0,0,2,0c.4-.44.23-1.12,0-2C15.72,2.8,15.16,1.82,15,1.88Z" />
<path d="M11,1.88c-.34.28-1.37-.35-2-1s-1.27-1.71-1-2,2.49.47,3,2C11,1,11.26,1.67,11,1.88Z" />
</g>
</pattern>
<clipPath id="tailMask">
<polygon class="tailMask" points="409,304 391,304 400,4 " />
</clipPath>
</defs>
<title>ballSpeed</title>
<g class="wholeBall">
<g class="ballShake">
<rect clip-path="url(#tailMask)" class="tail" x="391" y="4" width="18" rx="12" ry="12" height="300" fill="url(#tailGrad)" opacity="0.6" />
<circle class="ball" cx="400" cy="300" r="9" fill="#483127" />
<circle class="patt" cx="400" cy="300" r="9" fill="url(#asteroidPattern)" />
<circle class="asteroidGrad" cx="400" cy="300" r="9" fill="url(#asteroidGrad)" opacity="0.9" />
<!-- <circle class="glow" cx="400" cy="300" r="162" fill="url(#asteroidGlowGrad)" opacity="0.05"/> -->
<ellipse class="burnup" cx="400" cy="261" rx="33.5" ry="51" fill="url(#burnupGrad)" opacity="0.4" />
</g>
</g>
<g class="speedLines" fill="none" stroke="#FCF6B1" opacity="0.24" stroke-width="1">
<line x1="149.5" y1="471" x2="149.5" y2="237" />
<!-- <line x1="256.5" y1="182.5" x2="256.5" y2="60.5"/> -->
<line x1="582.5" y1="496" x2="582.5" y2="301" />
<line x1="353.5" y1="248.5" x2="353.5" y2="107.5" />
<line x1="460.5" y1="540" x2="460.5" y2="294" />
<line x1="423.5" y1="104" x2="423.5" y2="23" />
<line x1="709.5" y1="319.5" x2="709.5" y2="107.5" />
<line x1="509.5" y1="231.5" x2="509.5" y2="126.5" />
<line x1="306.5" y1="568.5" x2="306.5" y2="423" />
<line x1="604.5" y1="168.5" x2="604.5" y2="12.5" />
<line x1="61.5" y1="519" x2="61.5" y2="433" />
<!-- <line x1="31.5" y1="200.5" x2="31.5" y2="126.5"/> -->
<line x1="771.5" y1="517.5" x2="771.5" y2="375.5" />
</g>
</svg>
<script src='js/TweenMax.min.js'></script>
<script src='js/CustomWiggle.min.js'></script>
<script src='js/DrawSVGPlugin.js?r=12'></script>
<script src='js/CustomEase.min.js'></script>
<script>
var xmlns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink",
select = function(s) {
return document.querySelector(s);
},
selectAll = function(s) {
return document.querySelectorAll(s);
},
allSpeedLines = selectAll('.speedLines line'),
tailColor = select('.tailColor'),
burnupStop = select('.burnupStop'),
tailGradOffset = select('.tailGradOffset'),
ball = select('.ball'),
tail = select('.tail'),
burnup = select('.burnup'),
wholeBall = select('.wholeBall'),
ballShake = select('.ballShake'),
lineColorsArr = ['#A9E5BB', '#FCF6B1', '#F72C25', '#F7B32B'],
tailColorsArr = ['#F72C25', '#A9E5BB', '#FCF6B1', '#F72C25', '#F7B32B', '#00a9e5'],
burnupColorsArr = ['#F72C25', '#F72C25', '#FBEB22', '#FBEB22', '#FBEB22', '#FFF', '#FFF', '#FFF']
//console.log(allSpeedLines.length)
TweenMax.set('svg', {
visibility: 'visible'
})
TweenMax.set(allSpeedLines, {
drawSVG: '0% 0%'
})
TweenMax.set(ballShake, {
transformOrigin: '50% 50%'
})
CustomWiggle.create("ballDrop", {
wiggles: 60,
type: "random"
});
var gradShakeTl = new TimelineMax({
repeat: -1
});
var burnupTl = new TimelineMax({
repeat: -1
});
var ballPatternXTl = new TimelineMax({
repeat: -1,
yoyo: false
}).timeScale(2);
var ballPatternYTl = new TimelineMax({
repeat: -1,
yoyo: false
}).timeScale(2.82);
var ballShakeTl = new TimelineMax({
repeat: -1,
onUpdate: function() {
tailColor.setAttribute('stop-color', tailColorsArr[Math.floor(Math.random() * tailColorsArr.length)])
burnupStop.setAttribute('stop-color', burnupColorsArr[Math.floor(Math.random() * burnupColorsArr.length)])
burnupStop.setAttribute('stop-opacity', Math.random())
}
});
var ballTl = new TimelineMax({
repeat: -1,
yoyo: true
});
var linesTl = new TimelineMax({
repeat: -1
});
ballShakeTl.to(ballShake, 1, {
y: '-=5',
scale: 1.02,
ease: 'ballDrop'
})
gradShakeTl.to(tailGradOffset, 2, {
attr: {
offset: 0
},
ease: 'ballDrop'
})
burnupTl.to(burnup, 2, {
attr: {
rx: 23
},
ease: 'ballDrop'
})
ballTl.to(wholeBall, 2, {
y: 73,
ease: Sine.easeInOut
})
.to(wholeBall, 4, {
y: -70,
ease: Sine.easeInOut
}, '+=3')
.to(wholeBall, 8, {
y: 110,
ease: Sine.easeInOut
})
.to(wholeBall, 6, {
y: 0,
ease: Sine.easeInOut
})
ballPatternYTl.to('#asteroidPattern', 1.05, {
attr: {
x: '-=18'
},
ease: Linear.easeNone
})
ballPatternXTl.to('#asteroidPattern', 0.87, {
attr: {
y: '-=18'
},
ease: Linear.easeNone
})
function makeLines() {
var tl, l