Advertisement
oscarviedma

Funcionalidad JavaScript GSAP Revelar - OV DIVI

Feb 29th, 2024
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.1/gsap.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  2.  
  3. <script>
  4. jQuery(document).ready(function($){
  5. // Variables
  6. const body = document.body;
  7. const headFoot = $('.et-l.et-l--footer, .et-l.et-l--header, #main-header');
  8. const triggers = $('.ov-btn-revelar');
  9. const homeSection = $('.ov-seccion-revelar-principal > *');
  10. const backButtons = $('.ov-btn-revelar-regresar');
  11.  
  12. // Ajustes trigger
  13. triggers.each(function(){
  14. let listClassName = $(this).attr('class').split(' ');
  15. let revealClassName = String(listClassName[listClassName.indexOf(listClassName.find(element => element === 'ov-btn-revelar')) + 1]);
  16. const sectionReveal = $('.ov-revelar-contenido.' + revealClassName);
  17. const colReveal = $('.ov-revelar-contenido.' + revealClassName + ' .et_pb_column');
  18.  
  19. // Ajustes GSAP
  20. let tween = gsap.timeline({paused: true});
  21.  
  22. // Efecto Fade Out a la sección revelar principal
  23. tween.to(homeSection, {
  24. duration: 0.4,
  25. autoAlpha: 0,
  26. y: 40
  27. });
  28.  
  29. // Animación para revelar sección
  30. tween.to(sectionReveal, {
  31. duration: 0.6,
  32. delay: 0.2,
  33. y: 0,
  34. ease: "expo"
  35. });
  36.  
  37. // Animacion revelar columna
  38. tween.fromTo(colReveal, {
  39. delay: 0,
  40. delay: 0.4,
  41. clipPath: "polygon(-20% -20%, 120% -20%, 120% -20%, -20% -20%)"
  42. },
  43. {
  44. duration: 0.3,
  45. ease: "power1.inOut",
  46. stagger: 0.15,
  47. clipPath: "polygon(-20% -20%, 120% -20%, 120% 120%, -20% 120%)"
  48. }, "=-0.4");
  49.  
  50. // Reproducir animaciones al hacer clic en el botón
  51. $(this).on('click', function(e){
  52. e.preventDefault();
  53. body.classList.add('ov-contenido-open');
  54. tween.play();
  55. headFoot.toggleClass("hide");
  56. });
  57.  
  58. // Boton regresar - Revelar animación
  59. backButtons.on('click', function(){
  60. body.classList.remove('ov-contenido-open');
  61. tween.eventCallback("onReverseComplete", function(){
  62. headFoot.toggleClass("hide");
  63. });
  64. tween.reverse();
  65. });
  66. })
  67. });
  68. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement