Home CSS Lamp On Off Animation Using CSS

Lamp On Off Animation Using CSS

1704
0
SHARE

Bulb On Off Animation

Hello friend today with this article I am going to share with you a very beautiful Lamp On Off Animation Using CSS. Here you will get a Lamp and a button when you click on button Lamp will open and close.

It is a just like a game as we play with our siblings to on off the bulb using switch same here I am using a hidden checkbox operating threw a label where whenever we click on Label Off lamp or Bulb will be Animate to brighter that means lamp is on now and again when we click its gone off shade of light that means it is off now.

This bulb on off animation is a repetitive process on each click.

Before proceeding to coding part I would like to share with you my last two awesome article that will definitely blow your mind by their effect.

Please this out here as link given below:

  1. Image hover with slide out title
  2. I Love You Text Animation

So now lets start coding for this bulb on/off animation using css:

HTML Structure:

<div id="lamp">
  <input type="radio" name="switch" value="on" />
  <input type="radio" name="switch" value="off" checked="checked"/>
  <label for="switch" class="entypo-lamp"></label>
  <div class="lamp">
    <div class="gonna-give-light"></div>
  </div>
</div>

CSS Stylsheet:

@import url(http://weloveiconfonts.com/api/?family=entypo);
*, *:before, *:after {
  margin:0;
  padding:0;
  -webkit-box-sizing:border-box;
  -moz-box-sizing:border-box;
  box-sizing:border-box;
}
#lamp {
  position:relative;
  width:100vw;
  height:100vh;
  overflow:hidden;
}
input[name="switch"], input[name="switch"] + label {
  position:absolute;
  bottom:3rem;
  width:4rem;
  height:4rem;
}
input[name="switch"] + label {right:3rem;}
input[name="switch"] {
  opacity:0;
  z-index:9;
  cursor:pointer;
}
input[value="on"] {
  right:3rem;
}
input[value="off"] {
  right:-4rem;
}
input[name="switch"] + label {
  text-align:center;
}
[class*="entypo-"]:before {
  line-height:4rem;
  font-size:2.5rem;
  color:rgba(255,255,255,0.4);
  font-family:'entypo', sans-serif;
}
input[value="on"]:checked {
  right:-4rem;
}
input[value="on"]:checked + input[value="off"] {
  right:3rem;
}
.lamp {
  position:relative;
  margin:0 auto;
  width:.7rem;
  height:10rem;
  background-image:linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)),
                   linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)),
                   linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7));
  background-repeat:no-repeat;
  background-size:.15rem 8rem, .4rem .8rem, .7rem 2rem;
  background-position:50% 0, .19rem 8rem, 0 8.8rem;
}
.lamp:before, .lamp:after {
  content:'';
  position:absolute;
}
.lamp:before {
  left:-1.65rem;
  bottom:-4rem;
  width:4rem;
  height:4rem;
  border-radius:50%;
  background:rgba(255,255,255,0.03);
  box-shadow:inset 2px -2px 10px rgba(255,255,255,0.07);
  transition:all .15s;
}
.gonna-give-light, 
.gonna-give-light:before{
  position:absolute;
}
.gonna-give-light {
  top:10.05rem;
  left:.25rem;
  width:0;
  height:1.5rem;
  border-right:.2rem solid rgba(255,255,255,0.05);
}
.gonna-give-light:before {
  content:'';
  top:1.5rem;
  left:-.35rem;
  width:.9rem;
  height:.9rem;
  border-radius:50%;
  border:.2rem solid rgba(255,255,255,0.05);
  box-shadow:0px 0px 50px rgba(255,255,255,0);
}
input[value="on"]:checked ~ .lamp:before {
  background:rgba(255,255,255,1);
  box-shadow:0px 2px 10px rgba(255,255,255,0.8),
             0px 5px 50px rgba(255,255,255,0.8),
             0px 8px 80px rgba(255,255,255,0.6),
             0px 8px 120px rgba(255,255,255,0.6);
}
body {background:#2f323c;}
html, body {
  width:100%;
  height:100%;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here