/************* HAMBURGUER ****************/
window.onload = function () {
window.addEventListener('scroll', function (e) {
if (window.pageYOffset > 100) {
document.querySelector("header").classList.add('is-scrolling');
} else {
document.querySelector("header").classList.remove('is-scrolling');
}
});
const menu_btn = document.querySelector('.hamburger');
const mobile_menu = document.querySelector('.mobile-nav');
menu_btn.addEventListener('click', function () {
menu_btn.classList.toggle('is-active');
mobile_menu.classList.toggle('is-active');
});
};
/************* Ghost Halloween ****************/
var Ghost = function () {
var a = {};
if (jQuery.browser.msie) {
if (jQuery.browser.version < 8) {
return a;
}
}
a.html = '<div class="ghost"></div>';
a.element = null;
a.timer = null;
a.interval = Math.floor(Math.random() * 1e3) + 1e3;
a.directionX = Math.round(Math.random());
a.directionY = Math.round(Math.random());
if (a.directionX == 0) {
a.directionX = -1;
}
if (a.directionY == 0) {
a.directionY = -1;
}
a.screenWidth = null;
a.screenHeight = null;
a.elementWidth = 150;
a.elementHeight = 145;
a.init = function () {
a.getBrowserSize();
jQuery(window).resize(function () {
a.getBrowserSize();
});
a.element = jQuery(a.html);
a.timer = window.setInterval(a.move, a.interval);
jQuery("body").append(a.element);
a.move(true);
a.move();
return a;
};
a.move = function (b) {
var c = Math.floor(Math.random() * 100 + 100);
var d = Math.floor(Math.random() * 100 + 100);
var noi = a.element.offset().left;
var f = a.element.offset().top;
var g = noi + a.directionX * c;
var h = f + a.directionY * d;
var ino = a.screenWidth - a.elementWidth - 20;
var j = a.screenHeight - a.elementHeight;
if (g > ino) {
g = ino;
a.directionX = -a.directionX;
} else if (g < 0) {
g = 0;
a.directionX = -a.directionX;
}
if (h > j) {
h = j;
a.directionY = -a.directionY;
} else if (h < 0) {
h = 0;
a.directionY = -a.directionY;
}
var k = Math.random() - 0.1;
if (k < 0.4) {
k = 0.4;
}
if (b) {
a.element.css(
"top",
Math.floor(Math.random() * a.screenHeight - a.elementHeight)
);
a.element.css(
"left",
Math.floor(Math.random() * a.screenWidth - a.elementWidth)
);
} else {
a.element.removeClass("moving-left");
a.element.removeClass("moving-right");
if (g > noi) {
a.element.addClass("moving-right");
} else if (g < noi) {
a.element.addClass("moving-left");
}
a.element.stop();
a.element.animate(
{ top: h, left: g, opacity: k },
{ duration: a.interval, easing: "swing" }
);
}
};
a.getBrowserSize = function () {
a.screenWidth = jQuery(document).width();
a.screenHeight = jQuery(document).height();
};
a.init();
return a;
};
jQuery(function () {
var Ghosts = new Array();
for (var ino = 0; ino < 60; ino++) {
Ghosts.push(new Ghost());
}
});
// WHATSAPP NUMBER
function myWhats(){
let numWhatsapp = prompt("Numero de whatsapp sin espacios.");
let resultNum = 'https://api.whatsapp.com/send?phone=+52'+numWhatsapp+'&text=Hola';
console.log(resultNum);
document.getElementById("show_up").innerHTML = resultNum;
};
// SLIDER AUTOMÁTICO BANNER GRANDE //
document.addEventListener('DOMContentLoaded', function() {
const track = document.querySelector('.slider-track');
const slides = document.querySelectorAll('.slider-slide');
const dots = document.querySelectorAll('.slider-dot');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
let currentIndex = 0;
let slideWidth = slides[0].clientWidth;
let autoSlideInterval;
const slideCount = slides.length;
// Set up slider
function initSlider() {
slideWidth = slides[0].clientWidth;
track.style.width = `${slideWidth * slideCount}`;
// Set initial active dot
updateDots();
// Start auto slide
startAutoSlide();
// Handle window resize
window.addEventListener('resize', function() {
slideWidth = slides[0].clientWidth;
track.style.width = `${slideWidth * slideCount}`;
goToSlide(currentIndex);
});
}
// Go to specific slide
function goToSlide(index) {
if (index < 0) {
index = slideCount - 1;
} else if (index >= slideCount) {
index = 0;
}
currentIndex = index;
track.style.transform = `translateX(-${slideWidth * currentIndex}px)`;
updateDots();
// Reset auto slide timer
resetAutoSlide();
}
// Update navigation dots
function updateDots() {
dots.forEach((dot, index) => {
dot.classList.toggle('active', index === currentIndex);
});
}
// Auto sliding
function startAutoSlide() {
autoSlideInterval = setInterval(() => {
goToSlide(currentIndex + 1);
}, 5000);
}
function resetAutoSlide() {
clearInterval(autoSlideInterval);
startAutoSlide();
}
// Event listeners
prevBtn.addEventListener('click', () => {
goToSlide(currentIndex - 1);
});
nextBtn.addEventListener('click', () => {
goToSlide(currentIndex + 1);
});
// Dot navigation
dots.forEach((dot, index) => {
dot.addEventListener('click', () => {
goToSlide(index);
});
});
// Pause on hover
track.addEventListener('mouseenter', () => {
clearInterval(autoSlideInterval);
});
track.addEventListener('mouseleave', () => {
resetAutoSlide();
});
// Initialize slider
initSlider();
});
// MOSTRAR OCULTAR CONTENIDO DE MOVIES SERIES Y TV
function hidMvs() {
var x = document.getElementById("miDiv");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function hidMvs2() {
var x = document.getElementById("miDivTV");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function hidSeries() {
var x = document.getElementById("miDivSeries");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
// JUEGO DE TEMPORIZADOR 10 SEGUNDOS
let tiempoRef = Date.now()
let cronometrar = false
let acumulado = 0
function iniciar() {
cronometrar = true
}
function pausar() {
cronometrar = false
}
function reiniciar() {
acumulado = 0
}
setInterval(() => {
let tiempo = document.getElementById("tiempo")
if (cronometrar) {
acumulado += Date.now() - tiempoRef
}
tiempoRef = Date.now()
tiempo.innerHTML = formatearMS(acumulado)
}, 1000 / 60);
function formatearMS(tiempo_ms) {
let MS = tiempo_ms % 1000
//Agregué la variable St para solucionar el problema de contar los minutos y horas.
let St = Math.floor(((tiempo_ms - MS) / 1000))
let S = St%60
let M = Math.floor((St / 60) % 60)
let H = Math.floor((St/60 / 60))
Number.prototype.ceros = function (n) {
return (this + "").padStart(n, 0)
}
return H.ceros(2) + ":" + M.ceros(2) + ":" + S.ceros(2)
+ "." + MS.ceros(3)
}
// INDICE DE MASA CORPORTAL IMC
// peso / altura² 3.0276 = 29.3962
// peso / 2.89 = 22.49
// bajo peso 18.5
// peso normal 18.5 -24.9
// sobrepeso 25 - 29.9
// obesidad 30 o +
function imc_form(){
let s1 = document.getElementById('num1').value;
let s2 = document.getElementById('num2').value;
resultado = parseFloat(s1) / (parseFloat(s2)*s2);
texto_resultado = document.getElementById('result_imc');
texto_resultado.innerText = (resultado.toFixed(3));
}
function peso_form(){
let s3 = document.getElementById('num3').value;
resultado = s3 - 106;
texto_resultado = document.getElementById('resultado_peso');
texto_resultado.innerText = (resultado);
}