Ver Mensaje Individual
  #9 (permalink)  
Antiguo 09/04/2012, 12:52
Avatar de gjx2
gjx2
 
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: Cómo pasar de php a array de javascript

Hola Maru77 ,

Le hice unos ajuste al código para que te pueda permite la colocación de titulo y link fijate bien en los cambios.


Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4. $imgDb[1] = "http://i26.tinypic.com/11l7ls0.jpg";
  5. $imgDb[2] = "http://i29.tinypic.com/xp3hns.jpg";
  6. $imgDb[3] = "http://i30.tinypic.com/531q3n.jpg";
  7. $imgDb[4] =  "http://i31.tinypic.com/119w28m.jpg";
  8.  
  9.  
  10. foreach($imgDb as $id){
  11.  
  12. # Cree una matriz de dos dimenciones para poder tener el control de las  propiedades de cada imagen
  13. $img['img'][] = $id;
  14. $img['titulo'][] = "ejemplo imagen ".$id; //$ban->titulo;
  15. $img['link'][] = "http://".$id."/";  # Aqui colocas el link algun link
  16.  
  17. }
  18.  
  19. ?>
  20. <script type="text/javascript">
  21. window.onload = function(){
  22.  
  23. var img = new Array();
  24. var imagenes = <?=json_encode($img)?>
  25.  
  26. for(i=0;i<imagenes['img'].length;i++){
  27.    
  28.        
  29.      // Aqui realice otro cambio que espero lo notes.      
  30.     img[i] = new Array( imagenes['img'][i],imagenes['link'][i],"_new",imagenes['titulo'][i] );
  31.    
  32. }
  33.  
  34.  
  35. var mygallery=new simpleGallery({
  36.     wrapperid: "simplegallery1", //ID of main gallery container,
  37.     dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
  38.     imagearray:img,    
  39.     autoplay: [true, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
  40.     persist: false, //remember last viewed slide and recall within same session?
  41.     fadeduration: 500, //transition duration (milliseconds)
  42.     oninit:function(){ //event that fires when gallery has initialized/ ready to run
  43.         //Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))
  44.     },
  45.     onslide:function(curslide, i){ //event that fires after each slide is shown
  46.         //Keyword "this": references current gallery instance
  47.         //curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
  48.         //i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
  49.     }
  50. })
  51.  
  52.  
  53.  
  54. }
  55. </script>
  56. <div id="simplegallery1" style="width:500px"></div>