Gallery

Mostrando entradas con la etiqueta js. Mostrar todas las entradas
Mostrando entradas con la etiqueta js. Mostrar todas las entradas

jueves, 6 de agosto de 2026

JS - Creando el espacio en tu sitio web

 Espacio estelar en tu sitio web con Javascript


Código para no perder la línea--

Espero poder poner contenido dentro del espacio, que hasta ahorita no he podido.

-------------------------HTML5
<canvas id="canvas"></canvas>

-------------------------CSS3
#canvas{
    width: 100%;
    height: 150px;
    background: black;
}

-------------------------CSS3
// Canva espacial black and estrellas
  const canvas = document.getElementById('canvas');
  const ctx = canvas.getContext('2d');

  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;

  // Crear lista de estrellas
  const numEstrellas = 200;
  const estrellas = [];

  for (let i = 0; i < numEstrellas; i++) {
    estrellas.push({
      x: Math.random() * canvas.width,
      y: Math.random() * canvas.height,
      tam: Math.random() * 5,
      vel: Math.random() * 1.5 + 3.5 // Velocidad de movimiento
    });
  }

  function animar() {
    // Limpiar pantalla
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = 'white';

    // Actualizar y dibujar cada estrella
    estrellas.forEach(e => {
      e.x += e.vel; // Mover a la derecha

      // Si pasa el borde derecho, regresar a la izquierda (infinito)
      if (e.x > canvas.width) {
        e.x = 10;
        e.y = Math.random() * canvas.height; // Nueva posición vertical opcional
      }

      // Dibujar estrella
      ctx.fillRect(e.x, e.y, e.tam, e.tam);
    });

    requestAnimationFrame(animar);
  }

  animar(); Si logras poner contenido dentro del espacio, hay que compartir el como...

jueves, 30 de julio de 2026

JS - Protegiendo la página web

Proteger tu sitio web con un código simple pero poderoso con Javascript.

He acá hemos dejado el código para que puedan utilizarlo, copiar y pegar como siempre.

<script>validarPassword();</script>

function validarPassword(){
    texto = prompt("Para ver la página introduzca su contraseña");
    while(texto!="titojefe.123"){
        alert("Password incorrecta");
        texto = prompt("Para ver la página introduzca su contraseña");
    }
    alert("Password Correcta");
}

Y hay que dejar la fuente de donde lo encontramos. Origen Siempre hay que agradecer a quienes construyen herramientas para los demás.

domingo, 20 de julio de 2025

Slider con botones laterales y de localizacion

SLIDER CON BOTONES LATERALES Y DE LOCALIZACION.

CODIGO HTML5

<div class="slider-container">
            <div class="slider-track">
                <div class="slider-slide">
                    <img src="https://cdn-prod.puprod.indreams.me/"
                        alt="Resident Evil" class="slider-image">
                    <div class="slider-content">
                        <h2 class="slider-title">Shelly</h2>
                        <p class="slider-description">Conocida como
                            japonesa creada por Capcom.</p>
                    </div>
                </div>
                   
                <div class="slider-slide">
                    <img src="https://wotpack.ru/wp-content/uploads.jpg"
                            alt="Silent Hill" class="slider-image">
                    <div class="slider-content">
                        <h2 class="slider-title">Silent Hill</h2>
                        <p class="slider-description">Es una franquicia de videojuegos
                            publicada por Konami y su subsidiaria,
                                        Konami Digital Entertainment. </p>
                    </div>
                </div>

                <div class="slider-slide">
                    <img src="https://i.ytimg.com/vi/JwbhEACR8Vg/maxresdefault.jpg" alt="Dandys World" class="slider-image">
                    <div class="slider-content">
                        <h2 class="slider-title">Dandys World</h2>
                        <p class="slider-description">Es un juego multijugador de terror con mascotas creado por BlushCrunch Studio</p>
                    </div>
                </div>

                <div class="slider-slide">
                    <img src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/46cf2012-9552-434b-8a38-4b3bbc923fbe/diqzaqm-a8a1d40d-d3f0-48a6-8eb6-a0d378fcf6d0.jpg/v1/fill/w_1280,h_960,q_75,strp/dino_shelly_by_sweetzcherrys_diqzaqm-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9OTYwIiwicGF0aCI6IlwvZlwvNDZjZjIwMTItOTU1Mi00MzRiLThhMzgtNGIzYmJjOTIzZmJlXC9kaXF6YXFtLWE4YTFkNDBkLWQzZjAtNDhhNi04ZWI2LWEwZDM3OGZjZjZkMC5qcGciLCJ3aWR0aCI6Ijw9MTI4MCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.LDmrTRgdGZZEKARarcCDHoeakH61QQ2pF5ixbq4B93k" alt="Brawl Stars" class="slider-image">
                    <div class="slider-content">
                        <h2 class="slider-title">Brawl Stars</h2>
                        <p class="slider-description">Es un videojuego multijugador para móviles disponible en Android y iOS, desarrollado por Supercell y lanzado globalmente en 2018.</p>
                    </div>
                </div>

                <div class="slider-slide">
                    <img src="https://media.sketchfab.com/models/53c1f63911ef4c53b0053ce13c23b4fe/thumbnails/53d0ce722e49492d9d09514e9d7f4bfd/31e87f035af1447ab11d7a5f7ad97c95.jpeg" alt="God of War Ragnarok" class="slider-image">
                    <div class="slider-content">
                        <h2 class="slider-title">God of War Ragnarok</h2>
                        <p class="slider-description">Es un videojuego de acción y aventura hack and slash en tercera persona desarrollado por Santa Monica Studio y publicado por Sony Interactive Entertainment.</p>
                    </div>
                </div>
            </div>

            <div class="slider-nav">
                <button class="slider-btn prev">←</button>
                <button class="slider-btn next">→</button>
            </div>

            <div class="slider-dots">
                <div class="slider-dot"></div>
                <div class="slider-dot"></div>
                <div class="slider-dot"></div>
                <div class="slider-dot"></div>
                <!-- Al querer agregar o quitar una imagen nueva,
                tendremos que modificar estos botones,
                tienen que ir iguales 5==5 -->
                <div class="slider-dot active"></div>
            </div>
        </div>
   

CÓDIGO CSS


.slider-container {
    width: 100%; /*** ancho de donde esta la imagen, ajuste en px ***/
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}
.slider-track {
    display: flex;
    transition: transform 0.5s ease-in-out;
    height: 100vh; /*** alto de donde esta la imagen,
                    ajuste a la par de contaniner ***/
}
.slider-slide {
    min-width: 100%; /*** no mover este min-width ***/
    position: relative;
}
.slider-image {
    width: 100%; /*** va a la par de .slider-track ***/
    height: 100%; /*** va a la par de .slider-track ***/
    object-fit: cover;
}
.slider-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    color: white;
    padding: 30px;
    padding-top: 80px;
}
.slider-title {
    font-size: 2.2rem;
    margin-bottom: 10px;
    font-weight: 700;
}
.slider-description {
    font-size: 1rem;
    line-height: 1.6;
    max-width: 70%; /*** ajustar cada que se mueva el ancho en porcentajes,
                es para el texto ***/
}
.slider-nav {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}
.slider-btn {
    background-color: rgba(255, 255, 255, 0.7);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}
.slider-btn:hover {
    background-color: rgba(122, 19, 19, 0.9);
    transform: scale(1.1);
    color: white;
}
.slider-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 10;
}
.slider-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
}
.slider-dot.active {
    background-color: rgb(187, 255, 0);
    transform: scale(1.2);
}

CODIGO JS

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();
        });

Termina código del slider

domingo, 7 de enero de 2024

JS - Lateral Sidebar

Barra lateral para celular




HTML


<!------------- LATERAL SIDEBAR ------------->
  <div id="minimal_wall">
    <input type="checkbox" id="check">
    <label for="check">
      <img src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com
        /f/ce612125-96d6-4376-a8b3-6b72e463ad1e/
        d6s5d9m-8cbe2096-f452-42e1-a694-ffef7291a4b1.
        png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
        eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQ
        xNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY
        0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL
        2ZcL2NlNjEyMTI1LTk2ZDYtNDM3Ni1hOGIzLTZiNzJlNDYzYWQxZVwv
        ZDZzNWQ5bS04Y2JlMjA5Ni1mNDUyLTQyZTEtYTY5NC1mZmVmNzI5MWE0YjEucG
        5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.6aaql
        V2GiO50pnn90Oy8UOSg3pZWPf-hsCm7O0Mkevs"
        alt="" style="height: 60px" id="btn">
      <img src="img/cruzx.png" alt="" style="height: 26px" id="cancel">
    </label>

    <div class="sidebar">
        <header>Links</header>
        <ul>
            <li><a href="https://api.whatsapp.com/send/
                ?phone=+528117281794&text=Buen%20día,%20" target="_blank">
                <img src="img/whatsapplogo.jpg" alt="" style="height: 30px;
                vertical-align: middle; margin-right: 15px;"> Whatsapp</a></li>
            <li><a href="https://www.google.com/search?q=nfl+games&source=
                lmns&bih=611&biw=1366&rlz=1C1ONGR_enMX1040MX1040&hl=es&sa=X&ve
                d=2ahUKEwj10I-gm7WBAxU0JN4AHd79BacQ0pQJKAB6BAgBEAI" target="_blank">
                <img src="https://neiuindependent.org/wp-content/uploads/
                2019/11/nfl-national-football-league-royalty-free-thumbnail.jpg"
                 alt="" style="border-radius: 50px; height: 30px;
                vertical-align: middle; margin-right: 15px;">NFL</a></li>
            <li><a href="https://www.google.com/search?q=real+madrid&rlz=
                1C1ONGR_enMX1040MX1040&sxsrf=AJOqlzWXkyzXe3IZxTcO_cp9xrA4CBtr
                cw%3A1676834253739&ei=zXXyY9bjLLDbkPIPnYmWoAs&ved=0ahUKEwiW_qm
                wpqL9AhWwLUQIHZ2EBbQQ4dUDCA8&uact=5&oq=real+madrid&gs_lcp=Cgxnd
                3Mtd2l6LXNlcnAQAzIECCMQJzIECC4QJzILCAAQgAQQsQMQgwEyCwgAEIAEELED
                EIMBMggIABCxAxCDATIICAAQsQMQgwEyCwgAEIAEELEDEIMBMgsIABCABBCxAxC
                DATIFCAAQgAQyCAgAELEDEIMBOgoIABBHENYEELADOgUIIRCgAToQCAAQgAQQ
                FBCHAhCxAxCDAToKCAAQgAQQFBCHAjoFCC4QgAQ6CwguEIAEELEDEIMBSgQI
                QRgAUMAEWOQRYPoTaAFwAXgBgAGPAYgBvQiSAQM1LjWYAQCgAQHIAQjAA
                QE&sclient=gws-wiz-serp" target="_blank">
                <img src="img/rmadrid.png" alt="" style="border-radius: 50px;
                height: 35px; vertical-align: middle; margin-right: 15px;">
                Real Madrid</a></li>
        </ul>
    </div>
  </div>


CSS


/************ LATERAL SIDEBAR ************/
#minimal_wall{
    width: 100%;
    height: 0px;
    background: #042231;
}
.sidebar {
  position: fixed;
  left: -250px;
  width: 250px;
  height: 100%;
  background: #063146;
  transition: all .5s ease;
}
.sidebar header {
  font-size: 22px;
  color: white;
  line-height: 70px;
  text-align: center;
  background: #063146;
  user-select: none;
}
.sidebar ul a{
  display: block;
  height: 100%;
  width: 100%;
  line-height: 65px;
  font-size: 16px;
  color: white;
  padding-left: 40px;
  box-sizing: border-box;
  border-bottom: 1px solid black;
  border-top: 1px solid rgba(255,255,255,.1);
  transition: .4s;
}
.sidebar ul li:hover a{
  padding-left: 50px;
}
.sidebar ul a i{
  margin-right: 16px;
}
#check{
  display: none;
}
label #btn,label #cancel{
  position: absolute;
  background: #ffffff;
  border-radius: 50px;
  cursor: pointer;
  padding: 3px;
}
label #btn{
  left: 15px;
  top: 20px;
  font-size: 35px;
  color: white;
  transition: all .5s;
}
label #cancel{
  z-index: 1111;
  left: -195px;
  top: 20px;
  font-size: 30px;
  color: #0a5275;
  padding: 6px;
  transition: all .5s ease;
 
}
#check:checked ~ .sidebar{
  left: 0;
}
#check:checked ~ label #btn{
  left: 250px;
  opacity: 0;
  pointer-events: none;
}
#check:checked ~ label #cancel{
  left: 210px;
}


JAVASCRIPT


// nuevo diseño

posicionarMenu();
 
$(window).scroll(function() {    
    posicionarMenu();
});
 
function posicionarMenu() {
    var altura_del_header = $('.header').outerHeight(true);
    var altura_del_menu = $('.menu').outerHeight(true);
 
    if ($(window).scrollTop() >= altura_del_header){
        $('.menu').addClass('fixed');
        $('.wrapper').css('margin-top', (altura_del_menu) + 'px');
    } else {
        $('.menu').removeClass('fixed');
        $('.wrapper').css('margin-top', '0');
    }
}

sábado, 8 de julio de 2023

Javascript - Banner de varias imagenes

Crea un banner de varias imagenes manejable con botones



HTML

<div id="h_img">
   
        <img src="https://www.biology.ox.ac.uk/sites/default/files/
styles/mt_image_6_4/public/biology2/images/article/wildcru_tkpp.3_
c._justin_seymour_smith.jpg?itok=YoTotr4r" alt="" id="myDIV">

    <div id="buttones">
        <div id="button_0" onclick="btnRed()" ></div>
        <div id="button_0" onclick="btnGreen()"></div>
        <div id="button_0" onclick="btnBlue()"></div>
        <div id="button_0" onclick="btnReturn()"></div>
    </div>

</div>

CSS

#h_img{
    width: 100%;
    height: auto;
    display: flex;
    flex-flow: column;
    align-items: center;
    justify-content: center;
}
#h_img img{
    padding: 20px 0px 0px 0px ;
}
#buttones{
    width: 100%;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0px;
}
#button_0{
    width: 15px;
    height: 15px;
    background: white;
    border-radius: 10px;
    margin: 0px 20px;
    transition: all linear .25s;
}
#button_0:hover{
    background: red;
}
#button_0:nth-child(2){
    background: white;
}
#button_0:nth-child(2):hover{
    background: green;
}
#button_0:nth-child(3){
    background: white;
}
#button_0:nth-child(3):hover{
    background: blue;
}
#button_0:nth-child(4){
    background: white;
}
#button_0:nth-child(4):hover{
    background: yellow;
}

JAVASCRIPT

/******* las imagenes de preferencia que tengan
el mismo alto y ancho *******/

/******* HAMSTER *******/
function btnRed(){
    document.getElementById("myDIV").src="
https://i.pinimg.com/736x/23/a4/35/23a43593f24169de6829dd188752e1cb.jpg";
  }
  function btnRed2(){
      location.href="https://www.lawebdelprogramador.com/
foros/JavaScript/17119-Como-hago-un-link-con-Javascript.html";
  }

/******* GATO *******/
  function btnGreen(){
    document.getElementById("myDIV").src="
https://s1.1zoom.me/prev/592/Cats_Glance_Snout_591825_600x400.jpg";
  }
/******* PERRO *******/
  function btnBlue(){
    document.getElementById("myDIV").src="
https://st.depositphotos.com/30222024/51143/i/
450/depositphotos_511431526-stock-photo-three-dogs-playing-on-a.jpg";
  }
/******* LEON2 *******/
  function btnReturn(){
    document.getElementById("myDIV").src="
https://s1.1zoom.me/prev/504/503377.jpg";
  }



sábado, 13 de mayo de 2023

JS - Mostrar y ocultar div con un botón

 Muestra el contenido del "Div" con un solo botón en Javascript..



Así de sencillo fue el código.


HTML
<button onclick="myFunction()">Ver</button>
<div id="myDIV">
  <img src="https://humanidades.com/wp-content/uploads/
2016/07/buho-1-e1560041723608-800x400.jpg" alt="">
</div> CSS
#miDiv {
    display: none;
}


JS
function myFunction() {
    var x = document.getElementById("myDIV");
    if (x.style.display === "block") {
        x.style.display = "none";
    } else {
        x.style.display = "block";
    }
}


OPCION NUMERO 2

HTML5
<button class="btn_ab" onclick="openReal('primero')">TV-Online</button>
<div id='primero' class='real'>
    (contenido)
</div>


CSS
.real {
    width: 100%;
    height: auto;
    display: none;
}
.hidden {
    display: block !important;
}
.btn_ab{
    margin: 30px;
}


JAVASCRIPT

// Abrir y cerrar divs
function openReal(realName) {
    document.getElementById(realName).classList.toggle('hidden')
  }








Documental de Hackers