Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Transition on clip-path in a click toggle function

I've been trying to add a smooth transition in a toggle between a corner tab and the entire div.

The transition works with a background color (it changes slowly over 0.5s) but for some reason it won't work with the clip-path (I've tried clip-path and clipPath but neither works).

I'm guessing the problem goes deeper than my simple understanding of javascript so I'm turning to you pros for help. I want the tab to open/close slowly for 0.5s.

EDIT: I changed the value of the clip-path from none to ellipse(200% 200% at 100% 0) as suggested in an answer below. Unfortunately that didn't solve the problem because now I can't toggle the tab and entire div. Only press it once.

For some reason it won't run the value through my else statement when the clip-path is a value. It works for other styles; like background-color - but not for clip-path... I've tried for hours and I can't figure it out. Anybody out there who knows what is causing the problem?

/*vlog toggle*/
function toggleStyle(el, vlog, value) {
  if (el.style[vlog] !== value) {
    el.style[vlog] = value;
  } else {
    el.style[vlog] = '';
  }
}

var btn = document.querySelector("#vlog")
var div = document.querySelector("#vlog")
btn.addEventListener("click", function () {
  toggleStyle(div, "clipPath", "ellipse(200% 200% at 100% 0)")
});
#vlog {
width:300px;
height:300px;
background-color:#0a1227;
background-image:url('bg2.jpg');
background-size:100%;
background-repeat:no-repeat;
clip-path: ellipse(150px 150px at 100% 0);
position:absolute;
cursor:pointer;
top:0;
right:0;
z-index:999;
transition: background 1s, clip-path 0.5s;
}
<div id='vlog'></div>

Help is much appreciated!

Fred

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot transition to none

You can try adding a big shape like ellipse(200% 200% at 100% 0)

EDIT : I advise you to toggle a class instead of toggling style

var btn = document.querySelector("#vlog")
var div = document.querySelector("#vlog")
btn.addEventListener("click", function() {
  div.classList.toggle("full-size");
});
#vlog {
  width: 300px;
  height: 300px;
  background-color: #0a1227;
  background-image: url('bg2.jpg');
  background-size: 100%;
  background-repeat: no-repeat;
  clip-path: ellipse(150px 150px at 100% 0);
  position: absolute;
  cursor: pointer;
  top: 0;
  right: 0;
  transition:background 1s, clip-path 0.5s;
  z-index: 999;
}

#vlog.full-size {
  clip-path: ellipse(200% 200% at 100% 0);
  background: blue;
}
<div id='vlog'></div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda