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

79
Vistas
fancybox with vanilla js

I have a site with a zoom when a product image is clicked, and I was using fancybox. I wanted to get rid of fancybox so I created a simple function that appends some html to the DOM when the zoomModal method is called.

The tricky part is to open the modal with fancybox looks like this:

setTimeout(() => {
  $.fancybox.open({
    src: '.zoom-container', 
    type: 'inline', 
    opts: {
      modal: true
    }
  });
}, 150) 

We just have to set the src to the containing block which is shown below. I have this small block of code which is the zoom contents.

<div class="zoom-container">
      <div class="js-container_main_image">
        <img class="js-product-image" :src="selected_product.images[zoom_image_index].src" alt="" title="" />
      </div>
      <div class="zoom_thumbnails_container js-thumbnails_container">
        <div class="js-thumbs">
          <img class="js-product-image" 
               :class="{selected: zoom_image_index == imageIndex}"
               v-for="(image, imageIndex) in selected_product.images" 
               :src="_utils.resizeImage(image.src, 'x950')"
               :alt="image.alt" 
               :title="selected_product.title"
               @click="zoom_image_index = imageIndex" />
        </div>
      </div>
    </div>

Everything here works great and the vue directives work as they should. However without fancybox I have to call my modal like this

zoomModal.open()
const zoomContent = document.querySelector('.zoom-container').cloneNode(true)
document.querySelector('.zoom-modal').append(zoomContent)

and I lose the vue functionality. I don't understand what fancybox.open is doing that I can't seem to replicate in vanilla js. The only thing that works is if I use insertAdjacentElement but that is cut and paste and then when the zoom is opened a second then nothing works since remove() is called on the modal

about 4 years ago · Juan Pablo Isaza
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