Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Abrir fancybox desde la función

Estoy tratando de abrir un fancybox desde una función que tengo; en resumen, mi código HTML se ve así;

 <a href="#modalMine" onclick="myfunction(this); return false;"> click </a>

y una parte de mi función se ve así;

 function myfunction(me) { $(me).fancybox({ 'autoScale': true, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 500, 'speedOut': 300, 'autoDimensions': true, 'centerOnScroll': true, }); }

Lo anterior funciona en IE pero no en Firefox o Chrome. ¿Alguna idea de cómo puedo solucionar esto? Sé que uno de los motivos es activar otro enlace, pero espero que sea posible otra solución.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Si desea simplemente abrir un fancybox cuando se llama a una función de javascript. Tal vez en su flujo de código y no como resultado de un clic. Así es como lo haces:

 function openFancybox() { $.fancybox({ 'autoScale': true, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 500, 'speedOut': 300, 'autoDimensions': true, 'centerOnScroll': true, 'href' : '#contentdiv' }); }

Esto crea el cuadro usando "contentdiv" y lo abre.

over 4 years ago · Santiago Trujillo Report

0

Ya que está utilizando jQuery, deje de vincular controladores de eventos en su HTML y comience a escribir JavaScript discreto.

 $(document).ready(function () { function myfunction(me) { $(me).fancybox({ 'autoScale': true, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 500, 'speedOut': 300, 'autoDimensions': true, 'centerOnScroll': true // remove the trailing comma!! }).click(); // fire the click event after initializing fancybox on this element // this should open the fancybox } // use .one() so that the handler is executed at most once per element $('a[href=#modalMine]').one('click', function () { myfunction(this); return false; }); });

Sin embargo, particularmente no veo una razón para configurar el fancybox al hacer clic. Podrías hacer esto en su lugar:

 $(document).ready(function () { function myfunction() { // note the use of "this" rather than a function argument $(this).fancybox({ 'autoScale': true, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 500, 'speedOut': 300, 'autoDimensions': true, 'centerOnScroll': true }); } $('a[href=#modalMine]').each(myfunction); });

Demostración básica (sin imágenes) →

over 4 years ago · Santiago Trujillo Report

0

Lo que necesitas es:

 $.fancybox.open({ .... });

Consulte la sección "Métodos API" en la parte inferior de aquí:

http://fancyapps.com/fancybox/

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!