main.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Document on load event
  2. window.addEventListener('load', function () {
  3. document.getElementById("preloader").classList.add("fadehide");
  4. })
  5. // background
  6. var bg_image = document.querySelectorAll('.background'), i;
  7. for (i = 0; i < bg_image.length; ++i) {
  8. bg_image[i].style.backgroundImage = "url(" + bg_image[i].getAttribute('data-bg') + ")";
  9. };
  10. // toggle button
  11. (function () {
  12. var toggle = document.querySelector('.nav-switch');
  13. var parent = document.querySelector('.parent');
  14. var basic = document.querySelector('.basic-section')
  15. toggle.addEventListener('click', function () {
  16. parent.classList.toggle('action');
  17. });
  18. basic.addEventListener('click', function () {
  19. parent.classList.remove('action');
  20. });
  21. })();
  22. // appear
  23. let observedElements = document.querySelectorAll('.inview-element');
  24. // Define the elements you want to intiate an action on
  25. const options = { //define your options
  26. threshold: 0.5 //50% of the element in view
  27. }
  28. const inViewCallback = entries => {
  29. entries.forEach(entry => {
  30. if (entry.isIntersecting) { // define the event/property you want to use
  31. entry.target.classList.add('inview');
  32. //do something with the element
  33. }
  34. });
  35. }
  36. let observer = new IntersectionObserver(inViewCallback, options);
  37. // create a new instance using our callback which contains our elements and actions, using the options we defined
  38. observedElements.forEach(element => {
  39. observer.observe(element) // run the observer
  40. });
  41. // Glightbox
  42. var lightbox = GLightbox();
  43. lightbox.on('open', (target) => {
  44. console.log('lightbox opened');
  45. });
  46. var lightboxDescription = GLightbox({
  47. selector: '.glightbox2'
  48. });
  49. var lightboxVideo = GLightbox({
  50. selector: '.glightbox3'
  51. });
  52. lightboxVideo.on('slide_changed', ({ prev, current }) => {
  53. console.log('Prev slide', prev);
  54. console.log('Current slide', current);
  55. const { slideIndex, slideNode, slideConfig, player } = current;
  56. if (player) {
  57. if (!player.ready) {
  58. // If player is not ready
  59. player.on('ready', (event) => {
  60. // Do something when video is ready
  61. });
  62. }
  63. player.on('play', (event) => {
  64. console.log('Started play');
  65. });
  66. player.on('volumechange', (event) => {
  67. console.log('Volume change');
  68. });
  69. player.on('ended', (event) => {
  70. console.log('Video ended');
  71. });
  72. }
  73. });
  74. var lightboxInlineIframe = GLightbox({
  75. selector: '.glightbox4'
  76. });