Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 20

Discussione: Una specie di LightBox

  1. #1
    Utente di HTML.it L'avatar di gasmor
    Registrato dal
    Apr 2004
    Messaggi
    1,768

    Una specie di LightBox

    ola ,

    tutti conoscerete il bellissimo effetto Lightbox:

    http://www.huddletogether.com/projects/lightbox/

    io lo adoro e infatti l'ho usato tantissimo nel sito, tuttavia l'ho sempre ritenuto molto pesante con i suoi oltre 100kb di javascript.
    In realtà il solo lightbox pesa 24kb ma necessita di altre librerie che, almeno nel caso del mio sito specifico, non vengono più riutilizzate...

    Ollora ho pensato di realizzare qualcosa di simile riducendo il codice javascript il più possibile.
    Un esempio lo trovate in questa pagina: http://viaggiare.stragulp.com/blog/2...a_lisbona.html
    cliccate le immagini piccole per vedere l'effetto.

    Il javascript pesa 4,5kb quindi non aspettatevi troppo

    Riporto di seguito il codice:

    codice:
    function Settare() {	
    		if (!document.getElementsByTagName){ return; }
    		var anchors = document.getElementsByTagName('a');
    
    		for (var i=0; i<anchors.length; i++){
    			var anchor = anchors[i];
    			
    			var relAttribute = String(anchor.getAttribute('rel'));
    			
    			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('imgview'))){
    				//anchor.onclick = function () {open_img(this); return false;}
    				var contenuto = anchor.innerHTML.split('>');
    				contenuto = contenuto.join(' onClick="open_img(\''+anchor.getAttribute('href')+'\'); return false;" >');
    				anchor.innerHTML=contenuto;
    			}
    		}
    }
    
    //info schermo
    var wid = 1;
    var hig = screen.height;
    var max_width = screen.width-22;
    
    
    function open_img(elem){
    	backg = document.createElement("DIV");
    	backg.setAttribute("id", "baco");
    	backg.style.backgroundColor='#000';
    	backg.style.zIndex=100;
    	backg.style.width=wid+'px';
    	backg.style.height=hig+'px';
    	backg.style.position='absolute';
    	backg.style.left=0;
    	backg.style.top=0;
    	document.body.appendChild(backg);
    	fade('baco',95);
        sfondo(elem);
    	
    }
    
    //dati accelerazione
    var x=1;
    var t=2;
    var v = 6;
    
    function sfondo(elem){
       if(x>max_width) x = max_width;
       document.getElementById("baco").style.width = x+'px';
       if(x<max_width){
       x = x*(t/v)*t*t;
       window.setTimeout("sfondo('"+elem+"')", 7);
       }else{
       x=1;
       create_box(elem);
       }
    }
    
    var xx = Math.round(screen.availWidth / 2)-50; 
    var yy = Math.round(screen.availHeight / 2)-50; 
    
    	
    function create_box(elem){
    
    	boxel = document.createElement("DIV");
    	boxel.setAttribute("id", "box");
    	//boxel.setAttribute("style", "background-color:#fff; text-align:right; padding:10px; z-index:102; position:fixed; left:"+xx+"px; top:"+yy+"px;");
    	boxel.style.backgroundColor='#fff';
    	boxel.style.padding=10+'px';
    	boxel.style.zIndex=102;
    	boxel.style.position='absolute';
    	boxel.style.left=xx;
    	boxel.style.top=yy;
    	boxel.innerHTML = '<input type="button" id="buttonClose" name="buttonClose" value="X chiudi" onClick="chiudi_box()" style=" display:none; margin-bottom:15px">
    ';
    	boxel.innerHTML += '[img]cosa_fare_e_cosa_vedere_a_lisbona_files/loading.gif[/img]';
    	boxel.innerHTML += '[img]'+elem+'[/img]';
    	//boxel.innerHTML += '
    
    <input type="button" id="buttonClose" name="buttonClose" value="X chiudi" onClick="chiudi_box()" style=" display:none">';
    	document.body.appendChild(boxel);
    	setta_box();
    }
    
    function setta_box(){
    
       if(document.images['George'].width!=0 | document.images['George'].complete){
       document.getElementById("preload").style.display="none";
       document.getElementById("buttonClose").style.display="";
       x_new = xx - Math.round((document.images['George'].width+20) / 2);
       y_new = yy - Math.round((document.images['George'].height+20) / 2);
       document.getElementById("box").style.left = x_new+'px';
       document.getElementById("box").style.top = y_new+'px';
       fade('box',0,'piu');
       }else{
       window.setTimeout("setta_box();", 100);
       }
    }
    
    function chiudi_box(){
       cRemoveElement('box');
       cRemoveElement('baco');
    }
    
    function cRemoveElement(id) {
       var node = document.getElementById(id);
       
       if ((node) && (node.parentNode)) {
         var removed = node.parentNode.removeChild(node); 
         return true;
       }
    
       return false;
    }
    
    function fade(Target,opacity,option) {
                    fadeTarget = document.getElementById(Target);
                    if (opacity <= 100) {
                            if (fadeTarget.style.MozOpacity!=null) {
                                    fadeTarget.style.MozOpacity = (opacity/100);
                            } else if (fadeTarget.style.opacity!=null) {
                                    fadeTarget.style.opacity = (opacity/100);
                            } else if (fadeTarget.style.filter!=null) {
                                    fadeTarget.style.filter = "alpha(opacity="+opacity+")";
                            }
                    }
    				
    				if(option!='undefined'){
    				  if(option=='piu'){
    				    opacity += 10;
    				  }else if (option=='meno'){
    				    opacity -= 10;
    				  }
    				window.setTimeout("fade('"+Target+"',"+opacity+",'"+option+"')", 30);
    				}
    }
    
    function adatta(){
      hig = document.documentElement.scrollTop+screen.availHeight-50;
      yy = Math.round(screen.availHeight / 2)-50 + document.documentElement.scrollTop;
      if(document.getElementById("baco")!=null) document.getElementById("baco").style.height=hig+'px';
    }
    
    window.setTimeout("Settare()", 30);
    window.onscroll = adatta;
    Alcune funzioni sono state prese qui nel forum

    L'ho testao con firefox 1.5 IE 7.0 e Opera.

    Mi piacerebbe che mi aiutaste a migliorare il codice e che proviate a testarlo anche voi con i più svariati browser per verificare i bug.

    Allora, me la date una mano?
    Hai provato a creare un sito con Jaaxo Cms PHP5? new!

  2. #2
    Utente di HTML.it L'avatar di gasmor
    Registrato dal
    Apr 2004
    Messaggi
    1,768
    ho fatto alcune modifiche:


    codice:
    function Settare() {	
    		if (!document.getElementsByTagName){ return; }
    		var anchors = document.getElementsByTagName('a');
    
    		for (var i=0; i<anchors.length; i++){
    			var anchor = anchors[i];
    			
    			var relAttribute = String(anchor.getAttribute('rel'));
    			
    			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('imgview'))){
    				//anchor.onclick = function () {open_img(this); return false;}
    				var contenuto = anchor.innerHTML.split('>');
    				contenuto = contenuto.join(' onClick="open_img(\''+anchor.getAttribute('href')+'\'); return false;" >');
    				anchor.innerHTML=contenuto;
    			}
    		}
    }
    
    function open_img(elem){
    	backg = document.createElement("DIV");
    	backg.setAttribute("id", "baco");
    	backg.style.backgroundColor='#000';
    	backg.style.zIndex=100;
    	backg.style.width=1+'%';
    	backg.style.height=document.documentElement.scrollHeight+'px';
    	backg.style.position='absolute';
    	backg.style.left=0;
    	backg.style.top=0;
    	document.body.appendChild(backg);
    	fade('baco',95);
        sfondo(elem);
    	
    }
    
    //dati accelerazione
    var x=1;
    var t=2;
    var v = 6;
    
    function sfondo(elem){
       if(x>100) x = 100;
       document.getElementById("baco").style.width = x+'%';
       if(x<100){
       x = x*(t/v)*t*t;
       window.setTimeout("sfondo('"+elem+"')", 7);
       }else{
       x=1;
       create_box(elem);
       }
    }
    
    var xx = Math.round(screen.availWidth / 2)-50; 
    var yy = Math.round(screen.availHeight / 2)-50; 
    
    	
    function create_box(elem){
    
    	boxel = document.createElement("DIV");
    	boxel.setAttribute("id", "box");
    	//boxel.setAttribute("style", "background-color:#fff; text-align:right; padding:10px; z-index:102; position:fixed; left:"+xx+"px; top:"+yy+"px;");
    	boxel.style.backgroundColor='#fff';
    	boxel.style.padding=10+'px';
    	boxel.style.zIndex=102;
    	boxel.style.position='absolute';
    	boxel.style.left=xx;
    	boxel.style.top=yy;
    	boxel.innerHTML = '<input type="button" id="buttonClose" name="buttonClose" value="X chiudi" onClick="chiudi_box()" style=" display:none; margin-bottom:15px">
    ';
    	boxel.innerHTML += '[img]cosa_fare_e_cosa_vedere_a_lisbona_files/loading.gif[/img]';
    	boxel.innerHTML += '[img]'+elem+'[/img]';
    	//boxel.innerHTML += '
    
    <input type="button" id="buttonClose" name="buttonClose" value="X chiudi" onClick="chiudi_box()" style=" display:none">';
    	document.body.appendChild(boxel);
    	setta_box();
    }
    
    function setta_box(){
    
       if(document.images['George'].width!=0 | document.images['George'].complete){
       document.getElementById("preload").style.display="none";
       document.getElementById("buttonClose").style.display="";
       x_new = xx - Math.round((document.images['George'].width+20) / 2);
       y_new = yy - Math.round((document.images['George'].height+20) / 2);
       document.getElementById("box").style.left = x_new+'px';
       document.getElementById("box").style.top = y_new+'px';
       fade('box',0,'piu');
       }else{
       window.setTimeout("setta_box();", 100);
       }
    }
    
    function chiudi_box(){
       cRemoveElement('box');
       cRemoveElement('baco');
    }
    
    function cRemoveElement(id) {
       var node = document.getElementById(id);
       
       if ((node) && (node.parentNode)) {
         var removed = node.parentNode.removeChild(node); 
         return true;
       }
    
       return false;
    }
    
    function fade(Target,opacity,option) {
                    fadeTarget = document.getElementById(Target);
                    if (opacity <= 100) {
                            if (fadeTarget.style.MozOpacity!=null) {
                                    fadeTarget.style.MozOpacity = (opacity/100);
                            } else if (fadeTarget.style.opacity!=null) {
                                    fadeTarget.style.opacity = (opacity/100);
                            } else if (fadeTarget.style.filter!=null) {
                                    fadeTarget.style.filter = "alpha(opacity="+opacity+")";
                            }
                    }
    				
    				if(option!='undefined'){
    				  if(option=='piu'){
    				    opacity += 10;
    				  }else if (option=='meno'){
    				    opacity -= 10;
    				  }
    				window.setTimeout("fade('"+Target+"',"+opacity+",'"+option+"')", 30);
    				}
    }
    
    function adatta(){
      yy = Math.round(screen.availHeight / 2)-50 + document.documentElement.scrollTop;
    }
    
    window.setTimeout("Settare()", 30);
    window.onscroll = adatta;
    Hai provato a creare un sito con Jaaxo Cms PHP5? new!

  3. #3
    Utente di HTML.it L'avatar di stranyera
    Registrato dal
    Feb 2001
    Messaggi
    1,101
    a me con firefox non funziona

  4. #4
    Utente di HTML.it L'avatar di gasmor
    Registrato dal
    Apr 2004
    Messaggi
    1,768
    Originariamente inviato da stranyera
    a me con firefox non funziona
    Ciao,

    mi dici che versione di firefox hai usato e cosa ti accade di preciso?
    La foto ti si apre in un _blank?
    Hai provato a creare un sito con Jaaxo Cms PHP5? new!

  5. #5
    Utente di HTML.it L'avatar di stranyera
    Registrato dal
    Feb 2001
    Messaggi
    1,101
    Originariamente inviato da gasmor
    Ciao,

    mi dici che versione di firefox hai usato e cosa ti accade di preciso?
    La foto ti si apre in un _blank?
    ciao
    la versione di FF è la 2.0.0.6 e si, mi si apre in _blank

  6. #6
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732
    a me funziona bene, ed è una figata

    ho trovato solo un piccolo "bug", agevolo screenshot:



    praticamente rimane leggermente spostata in basso, e per vedere il fondo dell'immagine devi scendere nella pagina...

    a parte quello, mi piace molto

    se possibile, sarebbe una figata avere la possibilità di avere lo slideshow... a me piace molto questa soluzione:
    http://www.kreatura.hu/pyro/clearbox/cbtest/

  7. #7
    Utente di HTML.it L'avatar di gasmor
    Registrato dal
    Apr 2004
    Messaggi
    1,768
    grazie Inessuno per la dritta sulla slide vedrò di trovare una cosa simili da poter impiegare.

    Domani vedo di risolvere quel bug.

    Potresti gentilmente dirmi che versione di firefox hai usato?

    @stranyera

    ho fatto delle modifiche mi dici se il problema lo riscontri ancora?

    Grazie
    Hai provato a creare un sito con Jaaxo Cms PHP5? new!

  8. #8
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732
    firefox 2.0.0.6

    p.s. più la provo e più mi piace la tua bohbox (ma un nome ce l'ha? )

  9. #9
    Utente di HTML.it L'avatar di gasmor
    Registrato dal
    Apr 2004
    Messaggi
    1,768
    Il bug l'ho risolto.

    Il nome? SimpleLightbox
    Hai provato a creare un sito con Jaaxo Cms PHP5? new!

  10. #10
    Utente di HTML.it L'avatar di lnessuno
    Registrato dal
    Feb 2002
    Messaggi
    2,732
    mi piace sempre di più

    un altro piccolo bug: quando apro le immagini verticali, per vedere il pulsante di chiusura devo far scorrere leggermente in basso la pagina altrimenti rimane nascosto sotto la pagina...

    cmq se posso permettermi, suggerirei un nome un pò più accattivante... butto la un thinbox

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 © 2025 vBulletin Solutions, Inc. All rights reserved.