Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it L'avatar di Profeta
    Registrato dal
    Sep 2000
    Messaggi
    147

    Banner rotazione in tabella

    Ciao a tutti ho un problema devo creare una tabella con due celle in ogni cella devo inserire delle immagini a rotazione come se fossero dei banner e ogni volta che entro nella pagina l'immagine del banner deve essere causale il tutto se è possibile usando pagine html e non asp o php se è possibile. Chi mi può aiutare grazie di cuore

  2. #2
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    La tabella come dev'essere strutturata? Quante righe? Una riga con due celle o due righe con una cella ciascuna?

    Cosa intendi con immagini a rotazione? Le immagini variano una volta aperta la pagina o parli solamente della casualità dell'immagine visualizzata?

  3. #3
    Utente di HTML.it L'avatar di Profeta
    Registrato dal
    Sep 2000
    Messaggi
    147
    Per primo grazie per l'interessamento,una riga con due celle contenenti ogni cella immagini a rotazione come se fosse un banner e per quanto riguarda le immagini all’apertura della pagina l’immagine deve essere causale
    Grazie

  4. #4
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    Ma il tutto ti serve creato dinamicamente oppure la tabella c'è già? Le immagini che "girano" (stile banner) sono le stesse che possono aprirsi casualmente all'inizio?

  5. #5
    Utente di HTML.it L'avatar di Profeta
    Registrato dal
    Sep 2000
    Messaggi
    147
    Si le immagini sono le stesse purtroppo non ho niente secondo te cosa è meglio usare una tabella oppure pagine statiche

  6. #6
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    I banner devono essere contenuti in un collegamento? (cliccando sul banner succede qualcosa o sono solamente immagini che girano)

  7. #7
    Utente di HTML.it L'avatar di Profeta
    Registrato dal
    Sep 2000
    Messaggi
    147
    aiuto ti faccio disperare
    cliccando sull'immagine devo linkare a dei siti

  8. #8
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    Ok sto finendo di scrivere il codice...

  9. #9
    Utente di HTML.it L'avatar di Profeta
    Registrato dal
    Sep 2000
    Messaggi
    147
    cavolo sei troppo il millllliore

  10. #10
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    Ok, spero che vada (non l'ho provato)...

    bannersList = array contenente i percorsi (relativi o assoluti) delle immagini.
    anchorsList = array contenente gli href (relativi o assoluti) delle immagini.
    Più sotto c'è una riga con "delayBanner = 5000; // delay (millis) of banners change": cambia il 5000 (5 secondi) con il valore che ti serve (è il ritardo di rotazione del banner).
    L'ultimissima riga è "onload = appendBanners(dove);": cambia "dove" con il riferimento all'oggetto dove vuoi che compaia la tabella con i banner (mio consiglio: crea un div dove vuoi che appaiano i banner, attribuiscigli un id -es: divBanners- ed al posto di dove scrivi document.getElementById("divBanners").

    codice:
    var
      bannersList = new Array
      (
        "banner1.ext",
        "banner2.ext",
        "banner3.ext",
        "banner4.ext",
        "banner5.ext"
      ),
      anchorsList = new Array(
        "href1",
        "href2",
        "href3",
        "href4",
        "href5"
      ),
      firstBannerIndex,
      secondBannerIndex,
      firstBannerIndexNew,
      secondBannerIndexNew;
    
    function appendBanners(whereToAppend)
    {
    
      // variables
      var
        tableElement = document.createElement("table"),
        tableBodyElement = document.createElement("tbody"),
        tableRowElement = document.createElement("tr"),
        tableData1Element = document.createElement("td"),
        tableData2Element = document.createElement("td"),
        anchor1 = document.createElement("a"),
        anchor2 = document.createElement("a"),
        imageBanner1 = document.createElement("img"),
        imageBanner2 = document.createElement("img");
    
      // parent-children relations
      anchor1.appendChild(imageBanner1);
      anchor2.appendChild(imageBanner2);
      tableData1Element.appendChild(anchor1);
      tableData2Element.appendChild(anchor2);
      tableRowElement.appendChild(tableData1Element);
      tableRowElement.appendChild(tableData2Element);
      tableBodyElement.appendChild(tableRowElement);
      tableElement.appendChild(tableBodyElement);
    
      // images sources
      firstBannerIndex = Math.floor(Math.random() * bannersList.length);
      secondBannerIndex = Math.floor(Math.random() * bannersList.length);
    
      if (firstBannerIndex == secondBannerIndex) secondBannerIndex = (secondBannerIndex + 1) % bannersList.length;
      imageBanner1.setAttribute("src", bannersList[firstBannerIndex]);
      imageBanner2.setAttribute("src", bannersList[secondBannerIndex]);
      anchor1.setAttribute("href", anchorsList[firstBannerIndex]);
      anchor2.setAttribute("href", anchorsList[secondBannerIndex]);
      anchor1.setAttribute("target", "_blank");
      anchor2.setAttribute("target", "_blank");
    
      imageBanner1.style.border = imageBanner2.style.border = "0px";
    
      anchor1.setAttribute("id", "aBanner1");
      anchor2.setAttribute("id", "aBanner2");
    
      var
        delayBanner = 5000; // delay (millis) of banners change
    
      setInterval("changeBannerAndHref('" + anchor1.getAttribute("id") + "', '" + anchor2.getAttribute("id") + "')", delayBanner);
    
      whereToAppend.appendChild(tableElement);
    }
    function changeBannerAndHref(anchor1Id, anchor2Id)
    {
      firstBannerIndexNew = Math.floor(Math.random() * bannersList.length);
      secondBannerIndexNew = Math.floor(Math.random() * bannersList.length);
      if (firstBannerIndexNew == firstBannerIndex) firstBannerIndexNew = (firstBannerIndexNew + 1) % bannersList.length;
      while (secondBannerIndexNew == secondBannerIndex || secondBannerIndexNew == firstBannerIndexNew)
      {
        secondBannerIndexNew = (secondBannerIndexNew + 1) % bannersList.length;
      }
      firstBannerIndex = firstBannerIndexNew;
      secondBannerIndex = secondBannerIndexNew;
      document.getElementById(anchor1Id).setAttribute("href", anchorsList[firstBannerIndex]);
      document.getElementById(anchor2Id).setAttribute("href", anchorsList[secondBannerIndex]);
      document.getElementById(anchor1Id).childNodes[0].setAttribute("src", bannersList[firstBannerIndex]);
      document.getElementById(anchor2Id).childNodes[0].setAttribute("src", bannersList[secondBannerIndex]);
    }
    onload = function()
    {
      appendBanners(document.getElementById("appendHere"));
    }
    Spero che funzioni, fammi sapere se non va...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.