! Сегодня

Главная » Web и Технологии » Падающий снег для сайта на CSS и JS

Падающий снег для сайта на CSS и JS

Нашедший себя теряет зависимость от чужих мнений.

25-декабря-2023, 21:55   5   0

Падающий снег для сайта на CSS и JS

Включите «Волшебные моменты», возьмите уютное одеяло и целый день смотрите на этот фрагмент красивого падающего снега. За это вас никто не осудит! Увлекательная снежная анимация – это все, о чем вы можете мечтать в праздничные дни!

HTML

<svg class="svg-snowscene" xmlns="http://www.w3.org/2000/svg">
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
  <circle />
</svg>


SCSS

html {
  height: 100%;
}

body {
  height: 100%;
  background-image: 
   linear-gradient(
      to bottom in lch decreasing hue, 
      lch(36% 95 281) 0%, 
      lab(99% -148 -61) 100%
    );
}

.svg-snowscene {
  width: 100%;
  height: 50%;
}

circle {
  fill: #fff; 
  animation-name: snowing;
  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-out;
  &:nth-child(2n){
    animation-delay: 1.5s;
  }
  &:nth-child(3n){
    animation-delay: 2.3s;
    animation-duration: 3.3s;
  }
  &:nth-child(4n){
    animation-delay: 0.8s;
    animation-duration: 3.2s;
  }
  &:nth-child(5n){
    animation-delay: 2.8s;
  }
}

@keyframes snowing {
  0%{ fill-opacity: 1; }
  100% { 
    fill-opacity: 0;
    transform: translateY(100%);
  }
}


JS

const getRandom = (min, max) => {
  return Math.random() * (max - min) + min;
}

const letItSnow = () => {
  const snowflakes = document.querySelectorAll('circle');
  snowflakes.forEach((snowflake) => {
    snowflake.setAttribute('cx', getRandom(1,100) + '%');
    snowflake.setAttribute('cy', '-' + getRandom(1,100));
    snowflake.setAttribute('r', getRandom(1,3));
  })
};

letItSnow();


Поделиться

Tags

  • bowtiesmilelaughingblushsmileyrelaxedsmirk
    heart_eyeskissing_heartkissing_closed_eyesflushedrelievedsatisfiedgrin
    winkstuck_out_tongue_winking_eyestuck_out_tongue_closed_eyesgrinningkissingstuck_out_tonguesleeping
    worriedfrowninganguishedopen_mouthgrimacingconfusedhushed
    expressionlessunamusedsweat_smilesweatdisappointed_relievedwearypensive
    disappointedconfoundedfearfulcold_sweatperseverecrysob
    joyastonishedscreamtired_faceangryragetriumph
    sleepyyummasksunglassesdizzy_faceimpsmiling_imp
    neutral_faceno_mouthinnocent
2+2*2= ?

Редакторы выбирают

Web и Технологии