elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  Ayuda con javascript porfavor.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con javascript porfavor.  (Leído 2,236 veces)
HDS02

Desconectado Desconectado

Mensajes: 20



Ver Perfil
Ayuda con javascript porfavor.
« en: 14 Octubre 2010, 02:23 am »

Hola a todos..

Espero y me puedan ayudar con este codigo que me esta volviendo loco... yo no conozco mucho este lenguaje (javascript), y quiero modificar un pequeño codigo, que yo creo no es muy complicado. El codigo toma la imagen miniatura de un video de youtube y la muestra en un div, el problema es que yo quiero redimencionar esa imagen pero no se como, ya le intente de varias formas y no me sale, aqui el codigo...

Código
  1. jQuery.fn.ytplaylist = function(options) {
  2.  
  3.  // default settings
  4.  var options = jQuery.extend( {
  5.    holderId: 'ytvideo',
  6. playerHeight: '280',
  7. playerWidth: '325',
  8. addThumbs: false,
  9. thumbSize: 'small',
  10. showInline: false,
  11. autoPlay: true,
  12. showRelated: true,
  13. allowFullScreen: false
  14.  },options);
  15.  
  16.  return this.each(function() {
  17.  
  18.   var selector = $(this);
  19.  
  20. var autoPlay = "";
  21. var showRelated = "&rel=0";
  22. var fullScreen = "";
  23. if(options.autoPlay) autoPlay = "&autoplay=1";
  24. if(options.showRelated) showRelated = "&rel=1";
  25. if(options.allowFullScreen) fullScreen = "&fs=1";
  26.  
  27. //throw a youtube player in
  28. function play(id)
  29. {
  30.   var html  = '';
  31.  
  32.   html += '<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">';
  33.   html += '<param name="movie" value="http://www.youtube.com/v/'+id+autoPlay+showRelated+fullScreen+'"> </param>';
  34.   html += '<param name="wmode" value="transparent"> </param>';
  35.   if(options.allowFullScreen) {
  36.   html += '<param name="allowfullscreen" value="true"> </param>';
  37.   }
  38.   html += '<embed src="http://www.youtube.com/v/'+id+autoPlay+showRelated+fullScreen+'"';
  39.   if(options.allowFullScreen) {
  40.   html += ' allowfullscreen="true" ';
  41.   }
  42.   html += 'type="application/x-shockwave-flash" wmode="transparent"  height="'+options.playerHeight+'" width="'+options.playerWidth+'"></embed>';
  43.   html += '</object>';
  44.  
  45.   return html;
  46.  
  47. };
  48.  
  49.  
  50. //grab a youtube id from a (clean, no querystring) url (thanks to http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html)
  51. function youtubeid(url) {
  52. var ytid = url.match("[\\?&]v=([^&#38;#]*)");
  53. ytid = ytid[1];
  54. return ytid;
  55. };
  56.  
  57.  
  58. //load inital video
  59. var firstVid = selector.children("li:first-child").addClass("currentvideo").children("a").attr("href");
  60. $("#"+options.holderId+"").html(play(youtubeid(firstVid)));
  61.  
  62. //load video on request
  63. selector.children("li").children("a").click(function() {
  64.  
  65. if(options.showInline) {
  66. $("li.currentvideo").removeClass("currentvideo");
  67. $(this).parent("li").addClass("currentvideo").html(play(youtubeid($(this).attr("href"))));
  68. }
  69. else {
  70. $("#"+options.holderId+"").html(play(youtubeid($(this).attr("href"))));
  71. $(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo");
  72. $(this).parent("li").addClass("currentvideo");
  73. }
  74.  
  75.  
  76.  
  77. return false;
  78. });
  79.  
  80.  
  81. if(options.addThumbs) {
  82.  
  83. selector.children().each(function(i){
  84.  
  85. var replacedText = $(this).text();
  86.  
  87. if(options.thumbSize == 'small') {
  88.  
  89. var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/2.jpg";
  90. }
  91. else {
  92. var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/0.jpg";
  93. }
  94.  
  95.  
  96. $(this).children("a").empty().html("<img src='"+thumbUrl+"' alt='"+replacedText+"' />"+replacedText).attr("title", replacedText);
  97.  
  98. });
  99.  
  100. }
  101.  
  102.  
  103.  });
  104.  
  105. };


creo yo, la parte donde se tienen que poner los parametros es en esta parte del codigo:

$(this).children("a").empty().html("<img src='"+thumbUrl+"' alt='"+replacedText+"' />"+replacedText).attr("title", replacedText);

pero ya intente de varias formas y nomas no me funciona, espero alguien me puedan echar la mano.. se lo agradeceria mucho.

Gracias.


« Última modificación: 14 Octubre 2010, 02:26 am por Littlehorse » En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Ayuda con javascript porfavor.
« Respuesta #1 en: 14 Octubre 2010, 02:42 am »

Pero si te fijas, podes sacar la imagen directamente desde las imágenes de YOUTUBE. Así, supongamos que el video sea el siguiente,
Código
  1. "http://www.youtube.com/watch?v=".ZyvZ6sLfj2k;
para ver el THUMB es así,
Código
  1. "http://img.youtube.com/vi/".ZyvZ6sLfj2k."/default.jpg";

Supongo que deberías de agregarle esto,
Código
  1. $(this).children("a").empty().html(
  2.  "<img src='"+thumbUrl+"' alt='"+replacedText+"' height = '580' width= '525' />"+replacedText
  3. ).attr(
  4.  "title", replacedText
  5. );


En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
HDS02

Desconectado Desconectado

Mensajes: 20



Ver Perfil
Re: Ayuda con javascript porfavor.
« Respuesta #2 en: 14 Octubre 2010, 02:57 am »

K tal,

Gracias por responder tan rápido, mira efectivamente funciona, pero solo con "heigh" osea, solo me cambia ese valor, el otro width no me lo respeta.. el código lo tengo lo tengo exactamente asi.

$(this).children("a").empty().html("<img src='"+thumbUrl+"' height='100' width='100' alt='"+replacedText+"' />"+replacedText).attr("title", replacedText);

sabrás a que se deba??

gracias.

En línea

Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Ayuda con javascript porfavor.
« Respuesta #3 en: 14 Octubre 2010, 03:00 am »

Pues la verdad, ni idea. --Mi cerebro esta en otra cosa ahora--, de igual forma, solo puedo decirte, de que pondle lo siguiente,
Código
  1. $(this).children("a").empty().html(
  2.  "<img src='"+thumbUrl+"' alt='"+replacedText+"' height = '580px' width= '525px' />"+replacedText
  3. ).attr(
  4.  "title", replacedText
  5. );
En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
HDS02

Desconectado Desconectado

Mensajes: 20



Ver Perfil
Re: Ayuda con javascript porfavor.
« Respuesta #4 en: 14 Octubre 2010, 03:04 am »

Ok,

Gracias, de igual forma me ayudaste mucho, deja ver si puedo arreglar ese pequeño error ya es mas fácil..

saludos. 
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Añadir Estilo a javascript en HTML :: Ayuda Porfavor
Desarrollo Web
Cyber-Cyclop 1 2,840 Último mensaje 3 Noviembre 2012, 01:35 am
por peib0l
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines