svg环球旅行卡通动画效果

代码语言:html

所属分类:图表

代码描述:svg环球旅行卡通动画效果,奔跑的火车,点击星星会改变线路

代码标签: 卡通动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
* {
  box-sizing: border-box;
}
:root {
  --rotation-speed: 60;
  --size: 75;
  --train-size: 10;
  --train-speed: 25;
}
body {
  -webkit-box-align: center;
          align-items: center;
  background: #0d0d0d;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: center;
          justify-content: center;
  min-height: 100vh;
  overflow: hidden;
  font-family: sans-serif;
}
h1 {
  margin: 0;
  padding: 0;
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.scene {
  height: calc(var(--size) * 1vmin);
  position: absolute;
  width: calc(var(--size) * 1vmin);
  background: #1991e6;
  border-radius: 50%;
}
.globe {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  height: 100%;
  width: 100%;
}
.globe path {
  fill: #9c3;
  stroke: #453008;
  stroke-width: 1vmin;
  -webkit-transition: all calc(var(--transition-speed) * 1s) ease;
  transition: all calc(var(--transition-speed) * 1s) ease;
}
.train {
  -webkit-animation: travel calc(var(--train-speed) * 1s) infinite linear;
          animation: travel calc(var(--train-speed) * 1s) infinite linear;
  height: calc(var(--train-size) * 1vmin);
  left: 50%;
  offset-path: path(var(--path));
  position: absolute;
  -webkit-transition: all 0.25s ease;
  transition: all 0.25s ease;
  -webkit-transform: translate(0%, -50%) rotateX(0deg) rotateY(0deg);
          transform: translate(0%, -50%) rotateX(0deg) rotateY(0deg);
  top: 50%;
  width: calc(var(--train-size) * 1vmin);
}
.scene__cloud {
  height: calc(var(--height, 10) * 1%);
  width: calc(var(--width, 25) * 1%);
  background: #fff;
  border-radius: 25%/50%;
  position: absolute;
  top: 50%;
  left: 50%;
  opacity: var(--opacity);
  -webkit-transform-origin: center;
          transform-origin: center;
  -webkit-animation: float calc(var(--speed, 10) * 1s) calc(var(--delay, 2) * -1s) infinite linear var(--direction, normal);
          animation: float calc(var(--speed, 10) * 1s) calc(var(--delay, 2) * -1s) infinite linear var(--direction, normal);
}
.bubble circle,
.bubble rect {
  fill: hsl(0, 0%, calc(var(--lightness) * 1%));
}
.globe__face {
  width: calc(var(--size) * 0.5vmin);
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
}
.rock-or-hedge {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  -webkit-transform: translate(-50%, -25%);
          transform: translate(-50%, -25%);
  width: calc(var(--size) * 1vmin);
  height: calc(var(--size) * 1vmin);
  offset-path: path(var(--path));
  offset-distance: calc(var(--distance) * 1%);
  -webkit-transition: all 0.25s ease;
  transition: all 0.25s ease;
  background: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 1%));
}
.cedar {
  -webkit-transition: all 0.25s ease;
  transition: all 0.25s ease;
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--size) * 1vmin);
  -webkit-transform: translate(-50%, calc(var(--lightness) * -1%));
          transform: translate(-50%, calc(var(--lightness) * -1%));
  offset-path: path(var(--path));
  offset-distance: calc(var(--distance) * 1%);
}
.cedar rect {
  fill: hsl(20, calc(var(--saturation) * 1%), calc(var(--lightness) * 1%));
}
.cedar path {
  fill: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 1%));
}
.tree {
  -webkit-transition: all 0.25s ease;
  transition: all 0.25s ease;
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--size) * 1vmin);
  -webkit-transform: translate(-50%, calc(var(--lightness) * -1%));
          transform: translate(-50%, calc(var(--lightness) * -1%));
  offset-path: path(var(--path));
  offset-distance: calc(var(--distance) * 1%);
}
.tree rect:nth-of-type(1),
.tree rect:nth-of-type(3) {
  fill: hsl(20, calc(var(--saturation) * 1%), calc(var(--lightness) * 1%));
}
.tree rect:nth-of-type(2),
.tree circle {
  fill: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 1%));
}
.sound-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  height: 44px;
  width: 44px;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.sound-toggle path {
  fill: #fff;
}
.sound-toggle path:nth-of-type(2) {
  display: none;
}
.sound-toggle--active path:nth-of-type(1) {
  display: none;
}
.sound-toggle--active path:nth-of-type(2) {
  display: block;
}
@-webkit-keyframes rotate {
  to {
    -webkit-transform: rotate(-360deg);
            transform: rotate(-360deg);
  }
}
@keyframes rotate {
  to {
    -webkit-transform: rotate(-360deg);
            transform: rotate(-360deg);
  }
}
@-webkit-keyframes travel {
  to {
    offset-distance: 100%;
  }
}
@keyframes travel {
  to {
    offset-distance: 100%;
  }
}
@-webkit-keyframes float {
  from {
    -webkit-transform: translate(-50%, -50%) rotate(0deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
            transform: translate(-50%, -50%) rotate(0deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
  }
  to {
    -webkit-transform: translate(-50%, -50%) rotate(360deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
            transform: translate(-50%, -50%) rotate(360deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
  }
}
@keyframes float {
  from {
    -webkit-transform: translate(-50%, -50%) rotate(0deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
            transform: translate(-50%, -50%) rotate(0deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
  }
  to {
    -webkit-transform: translate(-50%, -50%) rotate(360deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
            transform: translate(-50%, -50%) rotate(360deg) translate(0, calc((var(--size) * var(--translation)) * 1vmin));
  }
}
</style>

</head>
<body translate="no">
<div class="scene">
<div class="scene__cloud" style="--delay: 36.475884207080995; --speed: 74.90171642257488; --opacity: 0.60694876381103; --height: 13.672005999241634; --width: 29.83190052884939; --direction: normal; --translation: 0.5426376708024705;"></div>
<div class="scene__cloud" style="--delay: 32.764812181599076; --speed: 72.76376426894961; --opacity: 0.6889826520758029; --height: 14.428479527387555; --width: 30.393892565835564; --direction: normal; --translation: 0.729387311773239;"></div>
<div class="scene__cloud" style="--delay: 49.401167794537145; --speed: 66.82488455964366; --opacity: 0.9457350621660343; --height: 10.08127992047525; --width: 16.101068240563823; --direction: normal; --translation: 0.5036394932780076;"></div>
<div class="scene__cloud" style="--delay: 57.48482396086436; --speed: 72.75599285282733; --opacity: 0.8999981537360584; --height: 11.037831188678682; --width: 22.765701111105834; --direction: normal; --translation: 0.511349459039727;"></div>
<div class="scene__cloud" style="--delay: 46.192617164704025; --speed: 65.79120565059418; --opacity: 0.5312913205645295; --height: 5.491459519056687; --width: 34.36365473364074; --direction: normal; --translation: 0.5814547382974294;"></div>
<div class="rock-or-hedge" style="--hue: 121.50935816712379; --saturation: 90.94428895260462; --lightness: 38.59190484079697; --size: 3.9172065564470575; --distance: 74.85591691997516;"></div>
<div class="rock-or-hedge" style="--hue: 116.62461182513962; --saturation: 91.54902280218101; --lightness: 40.232992662812826; --size: 3.363559970505109; --distance: 86.58085955979446;"></div>
<div class="rock-or-hedge" style="--hue: 95.88641460426973; --saturation: 14.255051933439573; --lightness: 72.1467580480043; --size: 2.1943121946646142; --distance: 96.66860379420415;"></div>
<div class="rock-or-hedge" style="--hue: 114.86894160055726; --saturation: 15.032506319540124; --lightness: 49.61760545992162; --size: 4.4926380711010125; --distance: 24.454652623264383;"></div>
<div class="rock-or-hedge" style="--hue: 97.57867283667886; --saturation: 14.359836852879443; --lightness: 68.03211183467073; --size: 5.419386789937258; --distance: 52.82976297464306;"></div>
<div class="rock-or-hedge" style="--hue: 119.42606858853853; --saturation: 91.43179636411011; --lightness: 58.59274014820996; --size: 1.0841003841381749; --distance: 95.65612502949125;"></div>
<div class="rock-or-hedge" style="--hue: 105.06474991875668; --saturation: 75.31202985334234; --lightness: 40.213787453324954; --size: 1.1970340422327754; --distance: 96.97637258539086;"></div>
<div class="rock-or-hedge" style="--hue: 90.64657673358963; --saturation: 20.42767709851744; --lightness: 27.25729862758478; --size: 5.809883341433431; --distance: 83.66258348830186;"></div>
<div class="rock-or-hedge" style="--hue: 121.98329121496312; --saturation: 85.52335577441954; --lightness: 34.34314448085033; --size: 1.4410006536641176; --distance: 31.447892345724316;"></div>
<div class="rock-or-hedge" style="--hue: 109.2441687262691; --saturation: 2.45904552658705; --lightness: 55.32843968503529; --size: 2.679943698447366; --distance: 19.441819030596207;"></div>
<div class="rock-or-hedge" style="--hue: 116.1717307117973; --saturation: 86.78898846273566; --lightness: 25.006703319762902; --size: 1.996198234366108; --distance: 14.831567878998753;"></div>
<div class="rock-or-hedge" style="--hue: 115.37368523892958; --saturation: 2.555145538446091; --lightness: 27.508599478893014; --size: 2.5262289923580363; --distance: 7.452706336437975;"></div>
<div class="rock-or-hedge" style="--hue: 99.84341247864688; --saturation: 4.955006350533159; --lightness: 72.02502814339371; --size: 4.63827077728326; --distance: 61.932537893711356;"></div>
<div class="rock-or-hedge" style="--hue: 109.16310824027477; --saturation: 87.31119705814919; --lightness: 48.17830185199168; --size: 5.34670021335727; --distance: 33.65408172950308;"></div>
<div class="rock-or-hedge" style="--hue: 124.55533216845804; --saturation: 90.0494593238183; --lightness: 34.92359719655531; --size: 3.252109562057366; --distance: 27.66051326442478;"></div>
<div class="rock-or-hedge" style="--hue: 119.19526048077958; --saturation: 89.40987466503107; --lightness: 70.88016066419209; --size: 4.050452408572654; --distance: 18.99518102409081;"></div>
<div class="rock-or-hedge" style="--hue: 101.74378503566369; --saturation: 77.40399414795712; --lightness: 30.545657067614016; --size: 5.228311098454018; --distance: 97.54041720551089;"></div>
<div class="rock-or-hedge" style="--hue: 101.14232962252686; --saturation: 77.2159448886722; --lightness: 33.811955268329775; --size: 3.3014094272720245; --distance: 26.568129920367788;"></div>
<div class="rock-or-hedge" style="--hue: 113.15884939663813; --saturation: 6.220844379905333; --lightness: 52.396844942631425; --size: 5.072105520278672; --distance: 39.35462499633584;"></div>
<div class="rock-or-hedge" style="--hue: 90.13953803213337; --saturation: 20.8556699977054; --lightness: 37.035874442903115; --size: 4.307385596623894; --distance: 76.94903985614098;"></div>
<svg class="cedar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 217" style="--hue: 92.15365570256196; --saturation: 90.18184040086783; --lightness: 38.095912554695886; --size: 3.729509823660522; --distance: 13.528361147457414;">
<g transform="translate(-39 -72)">
<rect width="30.2" height="103.6" x="74" y="185" ry="1.1"></rect>
<path d="M89 72l50 179H39L89 72z"></path>
</g>
</svg>
<svg class="cedar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 217" style="--hue: 99.19441068294144; --saturation: 86.73597604269101; --lightness: 46.08539320211121; --size: 1.9514562027608875; --distance: 42.48924905428475;">
<g transform="translate(-39 -72)">
<rect width="30.2" height="103.6" x="74" y="185" ry="1.1"></rect>
<path d="M89 72l50 179H39L89 72z"></path>
</g>
</svg>
<svg class="cedar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 217" style="--hue: 109.24928409290507; --saturation: 82.53104888212692; --lightness: 42.64731543809235; --size: 4.911295649386913; --distance: 80.07471189098369;">
<g transform="translate(-39 -72)">
<rect width="30.2" height="103.6" x="74" y="185" ry="1.1"></rect>
<path d="M89 72l50 179H39L89 72z"></path>
</g>
</svg>
<svg class="cedar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 217" style="--hue: 94.59633410889204; --saturation: 77.41623509053967; --lightness: 45.20748844137629; --size: 4.3016255482817725; --distance: 51.5900837238455;">
<g transform="translate(-39 -72)">
<rect width="30.2" height="103.6" x="74" y="185" ry="1.1"></rect>
<path d="M89 72l50 179H39L89 72z"></path>
</g>
</svg>
<svg class="cedar" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 217" style="-.........完整代码请登录后点击上方下载按钮下载查看

网友评论0