Foros del Web » Programando para Internet » Javascript »

Ayuda modificar script slideshow

Estas en el tema de Ayuda modificar script slideshow en el foro de Javascript en Foros del Web. Hola buenas, he conseguido un script slideshow al que me gustaría añadirle una mejora nada más: un enlace en cada imágen que pasa (lo ideal ...
  #1 (permalink)  
Antiguo 29/10/2007, 09:09
 
Fecha de Ingreso: noviembre-2003
Mensajes: 16
Antigüedad: 20 años, 5 meses
Puntos: 0
Ayuda modificar script slideshow

Hola buenas, he conseguido un script slideshow al que me gustaría añadirle una mejora nada más: un enlace en cada imágen que pasa (lo ideal sería un array con enlaces para que cada foto del array "Picture" muestre un enlace del array de elaces). El script es pequeño:

Código:
// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this
Picture[1] = '0580.jpg';
Picture[2] = '0583.jpg';
Picture[3] = '2011.jpg';
Caption[1] = "Texto1";
Caption[2] = "Texto2";
Caption[3] = "Texto3";
	
// =====================================
// Do not edit anything below this line!
// =====================================

var tss;
var iss;
var jss = 1;
var pss = Picture.length-1;

var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}

function runSlideShow(){
if (document.all){
document.images.PictureBox.style.filter="blendTrans(duration=2)";
document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
document.images.PictureBox.filters.blendTrans.Apply();}
document.images.PictureBox.src = preLoad[jss].src;
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= Caption[jss];
if (document.all) document.images.PictureBox.filters.blendTrans.Play();
jss = jss + 1;
if (jss > (pss)) jss=1;
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
¿Sabéis cómo podría modificarlo?
Graciasss
  #2 (permalink)  
Antiguo 29/10/2007, 10:30
 
Fecha de Ingreso: junio-2004
Mensajes: 621
Antigüedad: 19 años, 11 meses
Puntos: 25
Re: Ayuda modificar script slideshow

Hola,
te he modificado el script para que te funcione como tú quieres.
me he cepillado todos los arrays y lo he metido en un único array, cuyos elementos son de la forma
elemento[i] = ["imagen", "titulo de la imagen", "url del enlace"];

Le he puesto en enlace al texto. Pero se le puede poner a la imagen de la misma forma... Espero haberte ayudado.

Código:
// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var aPicture = new Array();
aPicture[0] = ["0580.jpg","texto 1","http://www.enlace1.com"];
aPicture[1] = ["0583.jpg","texto 2","http://www.enlace2.com"];
aPicture[2] = ["2011.jpg","texto 3","http://www.enlace3.com"];
	
// =====================================
// Do not edit anything below this line!
// =====================================

var tss;
var iss;
var jss = 1;
var pss = aPicture.length-1;

var preLoad = new Array();
for (iss = 0; iss < aPicture.length; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = aPicture[iss][0];}

function runSlideShow(){
if (document.all){
document.images.PictureBox.style.filter="blendTrans(duration=2)";
document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
document.images.PictureBox.filters.blendTrans.Apply();}
document.images.PictureBox.src = preLoad[jss].src;
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= "<a href=\"" + aPicture[jss][2] + "\">" + aPicture[jss][1] + "</a>";
if (document.all) document.images.PictureBox.filters.blendTrans.Play();
jss = jss + 1;
if (jss > (pss)) jss=1;
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
Le he cambiado la numeración al array y ahora empieza por 0. a lo mejor tienes que inicializar jss a 0, que se me ha olvidado comprobarlo.
__________________
eContento
- Mis artículos y tutoriales
- Mis jsfiddles
  #3 (permalink)  
Antiguo 29/10/2007, 16:15
 
Fecha de Ingreso: noviembre-2003
Mensajes: 16
Antigüedad: 20 años, 5 meses
Puntos: 0
Re: Ayuda modificar script slideshow

Muchas gracias! Voy ahora a probarlo. Pero sobre todo me interesaba poner el enlace a la imágen además del texto, ya que con mis nulos conocimientos de javascript era lo que había conseguido, pero no lo de la imágen. A ver si puedes decirme cómo hago para que además el link salga en la imágen. Sería entonces perfecto.

Gracias!
  #4 (permalink)  
Antiguo 30/10/2007, 01:07
 
Fecha de Ingreso: junio-2004
Mensajes: 621
Antigüedad: 19 años, 11 meses
Puntos: 25
Re: Ayuda modificar script slideshow

Es que no sé la estrcutura HTML porque no la pones.
Pero supongo que la imagen estará dentro de un contenedor DIV, SPAN o TD. Sólo hay que añadirle un id="divImg" o algo así.

y luego poner
Código:
if (document.getElementById) document.getElementById("divImg").innerHTML= "<a href=\"" + aPicture[jss][2] + "\">" + codigoImagen + "</a>";
donde codigoImagen es el HTML que tengas tú puesto para la imagen, con su correspondiente id="PicturteBox".

A ver si ahora sí que sí
__________________
eContento
- Mis artículos y tutoriales
- Mis jsfiddles
  #5 (permalink)  
Antiguo 30/10/2007, 05:20
 
Fecha de Ingreso: noviembre-2003
Mensajes: 16
Antigüedad: 20 años, 5 meses
Puntos: 0
Re: Ayuda modificar script slideshow

Perdona, es cierto, olvidé esa parte HTML que es:

Código:
<table cellpadding="0" cellspacing="0">
  <tr>
    <!--
    The next table cell holds the images.
    Set cell and image width and height the same.
    The img src must have name=PictureBox in its
    tag.  Usually the first image in the Picture
    array in the script is used here.
    //-->
    <td width=175 height=210>
    <img src=imagenes/defaultcaption.gif name=PictureBox width=175 height=210></td>
  </tr>
  <tr>
    <!-- 
    The next table cell holds the captions.
    This table cell must have id=CaptionBox and
    class=Caption in its tag. The default caption
    shows whilst loading in all browsers; NS4
    will show only the default caption, throughout.
    //-->
    <td id=CaptionBox class=Caption align=center bgcolor=yellow>
    &nbsp;<br>&nbsp;
    </td>
  </tr>
</table>
  #6 (permalink)  
Antiguo 30/10/2007, 05:49
 
Fecha de Ingreso: junio-2004
Mensajes: 621
Antigüedad: 19 años, 11 meses
Puntos: 25
Re: Ayuda modificar script slideshow

Hola,
Efectivamente es como pensaba.
En el mensaje previo entonces te explicaba qé debías hacer para que funcionara.
Pruebalo y me dices.

No me importa dártelo hecho, pero creo que es mejor que llegues a la solución por tu cuenta. Si te rindes, mañana te pongo todo el código. Pero ya no estás muy lejos.

Un saludo de,
eContento
__________________
eContento
- Mis artículos y tutoriales
- Mis jsfiddles
  #7 (permalink)  
Antiguo 22/11/2007, 06:45
 
Fecha de Ingreso: noviembre-2003
Mensajes: 16
Antigüedad: 20 años, 5 meses
Puntos: 0
Re: Ayuda modificar script slideshow

eContento, lo he conseguido pero para IExplorer, no para Firefox. ¿Sabrías cómo hacer que se viera también en Firefox?

Este es el código que me funciona bien en IExplorer:

Código:
// (C) 2002 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// ==============================
// Set the following variables...
// ==============================

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this
var PC = new Array();

Picture[1] = '3002.jpg';
	Picture[2] = '0580.jpg';
	Picture[3] = '0583.jpg';
	Picture[4] = '2011.jpg';
	Caption[1] = "<a href='pag.php'>texto1</a>";
	Caption[2] = "<a href='pag.php'>texto2</a>";
	Caption[3] = "<a href='pag.php'>texto3</a>";
	Caption[4] = "<a href='pag.php'>texto4</a>";
	PC[1] = 'pag.php/'
	PC[2] = 'pag.php/'
	PC[3] = 'pag.php/'
	PC[4] = 'pag.php/'
	
// =====================================
// Do not edit anything below this line!
// =====================================

var tss;
var iss;
var jss = 1;
var pss = Picture.length-1;
var Imagen = "<img src=imagenes/defaultcaption.gif name=PictureBox width=175 height=210>";


var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}

function runSlideShow(){
if (document.all){
if (document.getElementById) document.getElementById("divImg").innerHTML= "<a class='nada' target='_self' href=' " + PC[jss] + " '> " + Imagen + "</a>";
document.images.PictureBox.style.filter="blendTrans(duration=2)";
document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
document.images.PictureBox.filters.blendTrans.Apply();}
document.images.PictureBox.src = preLoad[jss].src;
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= Caption[jss];
if (document.all) document.images.PictureBox.filters.blendTrans.Play();
jss = jss + 1;
if (jss > (pss)) jss=1;
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
Con el HTML siguiente:
Código:
<table width="175" cellpadding="0" cellspacing="0" class="promociones">
  <tr>
      <td width=175 height=210 id=divImg>

    </td>
  </tr>
  <tr>
       <td id=CaptionBox class=Caption align=center bgcolor=yellow>
    &nbsp;<br>&nbsp;
    </td>
  </tr>
</table>
  #8 (permalink)  
Antiguo 23/11/2007, 03:13
 
Fecha de Ingreso: junio-2004
Mensajes: 621
Antigüedad: 19 años, 11 meses
Puntos: 25
Re: Ayuda modificar script slideshow

Hola apawiper,

En este momento me pillas muy liado. Pero en cuanto tenga 5 minutillos estudio tu caso ¿ok?
A ver si mientras te puede ayudar alguien, que por aquí hay gente que sabe mucho.

Un saludo de,
eContento
__________________
eContento
- Mis artículos y tutoriales
- Mis jsfiddles
  #9 (permalink)  
Antiguo 23/11/2007, 07:00
 
Fecha de Ingreso: noviembre-2003
Mensajes: 16
Antigüedad: 20 años, 5 meses
Puntos: 0
Re: Ayuda modificar script slideshow

Ok muchas gracias, tú tómate tu tiempo.
El error exacto según la Consola de errores de Java del Firefox es:

"document.images.PictureBox.src has no properties"

Gracias y Un saludo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:40.