HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"> </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style> #bulb-svg { transition: all .4s ease-in-out; width:100%; margin:0 auto; } .switch-line{ cursor: pointer; width: 55px; height: 14px; background-color: #9e9e9e; margin: 0 auto; position: relative; border-radius: 20px; } .switch-dot{ position: absolute; top: -5px; left: 0px; width: 25px; height: 25px; border-radius: 50%; background-color: #fff; transition: all 0.1s; -webkit-transition: all 0.1s; animation-delay: 0.1s; -webkit-animation-delay: 0.1s; border: 1px solid #d9d9d9; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14), 0 2px 1px -1px rgba(0, 0, 0, 0.12); } </style> </head> <body> <svg id="bulb-svg" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="196px" height="196px" viewBox="0 0 196 196" enable-background="new 0 0 196 196" xml:space="preserve"> <g id="bulb"> <path id="bulb_body" fill="#FFFFFF" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M138,86.465 c0-22.284-18.131-40.348-40.5-40.348c-22.367,0-40.5,18.064-40.5,40.348c0,13.2,6.363,24.918,16.201,32.279v12.91 c0,1.781,1.449,3.229,3.238,3.229h42.12c1.789,0,3.24-1.445,3.24-3.229v-12.91C131.637,111.384,138,99.665,138,86.465z"/> <g id="sockel"> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M119.013,139.598 c0,1.803-1.468,3.266-3.276,3.266H79.689c-1.81,0-3.276-1.463-3.276-3.266l0,0c0-1.805,1.468-3.267,3.276-3.267h36.046 C117.545,136.331,119.013,137.793,119.013,139.598L119.013,139.598z"/> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M119.013,146.128 c0,1.804-1.468,3.267-3.276,3.267H79.689c-1.81,0-3.276-1.463-3.276-3.267l0,0c0-1.804,1.468-3.267,3.276-3.267h36.046 C117.545,142.861,119.013,144.324,119.013,146.128L119.013,146.128z"/> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M119.013,152.659 c0,1.804-1.468,3.267-3.276,3.267H79.689c-1.81,0-3.276-1.463-3.276-3.267l0,0c0-1.804,1.468-3.267,3.276-3.267h36.046 C117.545,149.395,119.013,150.855,119.013,152.659L119.013,152.659z"/> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M119.013,159.191 c0,1.803-1.468,3.266-3.276,3.266H79.689c-1.81,0-3.276-1.463-3.276-3.266l0,0c0-1.805,1.468-3.267,3.276-3.267h36.046 C117.545,155.926,119.013,157.389,119.013,159.191L119.013,159.191z"/> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-miterlimit="10" d="M89.111,168.988c0,4.093,3.851,7.41,8.602,7.41 c4.75,0,8.603-3.317,8.603-7.41"/> <path fill="#C0C0C0" stroke="#3D3D3D" stroke-width="3" stroke-miterlimit="10" d="M81.116,162.457v3.266 c0,1.805,1.467,3.267,3.275,3.267h4.72h17.203h4.293c1.809,0,3.275-1.464,3.275-3.267v-3.266"/> </g> <path fill="none" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M75,89.781v2.427v6.953 l13,12.769v22.75"/> <path fill="none" stroke="#3D3D3D" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M107,134.68v-22.75 l13-12.769v-6.953v-2.427"/> <path id="glow" fill="none" stroke="#FFFFFF" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" d="M120,89.802 c0,3.003-2.52,5.438-5.625,5.438c-3.107,0-5.625-2.435-5.625-5.438c0,3.003-2.52,5.438-5.625,5.438 c-3.107,0-5.625-2.435-5.625-5.438c0,3.003-2.519,5.438-5.625,5.438s-5.625-2.435-5.625-5.438c0,3.003-2.519,5.438-5.625,5.438 c-3.105,0-5.625-2.435-5.625-5.438"/> </g> <g id="licht" style="opacity:0"> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="151.088" y1="90.5" x2="170" y2="90.5"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="25" y1="90.5" x2="43.912" y2="90.5"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="135.392" y1="128.327" x2="148.765" y2="141.677"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="46.234" y1="39.322" x2="59.607" y2="52.673"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" stroke-opacity="0" x1="97.5" y1="143.996" x2="97.5" y2="162.876"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="97.5" y1="18.124" x2="97.5" y2="37.004"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="59.607" y1="128.327" x2="46.234" y2="141.677"/> <line fill="none" stroke="#96BF1F" stroke-width="3" stroke-linecap="square" stroke-miterlimit="10" x1="148.765" y1="39.322" x2="135.392" y2="52.672"/> </g> </svg> <div class="switch-line"> <div class="switch-dot"></div> </div> <p><strong>Note</strong>: This example is intended for demo purpose and not for understanding purpose.</p> <script> var select = function(s) { return document.querySelector(s); }, selectAll = function(s) { return document.querySelectorAll(s); }, svg = $("#bulb-svg"), bulb_full = select("#bulb"), bulb = select("#bulb_body"), licht = select("#licht"), glow_on = select("#glow"); $('#bulb-svg').on("load", function() { var licht_init = new TimelineLite(); TweenMax.set(licht, { opacity: 0, scale: 0.6, transformOrigin: "50% 50%" }); TweenMax.set(glow, { opacity: 1, transformOrigin: "50% 50%", stroke: "#3D3D3D" }); }); $(".switch-line").click(function(){ if($(this).children(".switch-dot").css('left') =="30px"){ $(this).children(".switch-dot").css({"left":"0px","border":"1px solid #d9d9d9","background":"#fff","box-shadow": "0 1px 3px 0 rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12)"}); $(this).css({"background":"rgb(158,158,158)"}); $(this).children(".switch-dot").removeClass("mywave"); } else{ $(this).children(".switch-dot").css({"left":"30px","border":"none","background":"#106cc8","box-shadow": "none"}); $(this).children(".switch-dot").addClass("mywave"); $(this).css({"background":"#b8d9f9"});; } }); $(".switch-line").click(function(){ if($(".switch-dot").css('left') !="30px"){ TweenMax.to(bulb_body, 0.3, { opacity: 1, fill: "#96BF1F" }); TweenMax.to(licht, 0.3, { opacity: 1, scale: 1 }), TweenMax.to(glow, 0.3, { opacity: 1, stroke: "#FFFFFF" }); TweenMax.fromTo(licht, 0.8, { scale: 1, },{ scale: 1.1, repeat: -1, yoyo: true }); } else{ TweenMax.to(bulb_body, 0.4, { opacity: 1, fill: "#FFFFFF" }); TweenMax.to(licht, 0.3, { opacity: 0, scale: 0.8 }), TweenMax.to(glow_on, 0.3, { opacity: 1, stroke: "#3D3D3D" }); } }); </script> </body> </html>
OUTPUT
×

Save as Private