如何调整 YouTube 播放器的大小,从缩略图大小调整为“正常”大小尺寸
我想这与 Facebook 的做法类似,但是……我还没有弄清楚如何遵循他们的做法,如果这是一个骗局,我深表歉意。
我们的想法是拥有一个缩略图大小的播放器 (width="220px"
height="180px"
),当单击时,它会调整为“正常”大小(正常)当然是任意的,但就本例而言,如果我们使用 width="445px"
、height="364px"
作为 Youtube 默认值),然后播放。
我假设 onClick 事件应该更改
以下视频是我打算使用的视频之一,在这里给出一个真实的示例:
<object class="yt" width="445" height="364">
<param name="movie" value="http://www.youtube.com/v/2ieLb3RAblA&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&border=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/2ieLb3RAblA&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed>
</object>
作为附录,这可能会在静态 html 页面中使用一段时间,然后移动到 php ( 5.2) 网站不久之后,php 和 html 都链接了 jQuery 1.3.2,并且我非常乐意使用第三方插件(如果存在)可以轻松完成此操作。
感谢任何和所有的帮助,我很抱歉问什么可能 - 并且对我来说 - 似乎是一个愚蠢的问题。我想这应该是显而易见的。
提前致谢。
I guess this is similar to what Facebook does, but...I haven't worked out how to follow what they do and if this is a dupe, I apologise.
The idea is to have a thumbnail-size player (width="220px"
height="180px"
) that, when clicked, resizes to a 'normal' size (normal is arbitrary, of course, but for the sake of this example, if we go with width="445px"
, height="364px"
as the Youtube default) and then plays.
I'm assuming that the onClick event should change the height and width properties defined in the <object>
and <embed>
tags, but since the object is flash I assume the flash player 'captures' the clicks rather than reporting them to the browser?
The following video is one of those I intend to use, and is here to give a real-world example:
<object class="yt" width="445" height="364">
<param name="movie" value="http://www.youtube.com/v/2ieLb3RAblA&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&border=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/2ieLb3RAblA&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed>
</object>
As an addenda, this is likely to be used in a static html page for a short while, and be moved to a php (5.2) site shortly afterwards, both php and html have jQuery 1.3.2 linked, and I'm more than happy to use a third-party plugin if such exists to do this easily.
Any and all help is appreciated, I'm sorry for asking what may -and does, to me- appear to be a dumb question. It should be obvious, I guess.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Facebook 使用了一个看起来像播放器的缩略图——巧妙的技巧。我找到了一个 jQuery 插件 youtube 缩略图,我还没试过。
一些示例代码:
JS:
我打开了自动播放,因为如果用户单击图像,您可能需要这样做。这应该是集成到您的应用程序中的良好起点。 jQuery 插件唯一做的就是获取缩略图的 url - 您可以获取大图像或小图像。
Facebook uses a thumbnail that just looks like a player - neat trick. I found a jQuery plugin that can get youtube thumbnails, I haven't tried it though.
Some sample code:
And the JS:
I turned autoplay on since you probably want that if the user is clicking on the image. This should be a good starting point for integrating into your app. The only thing the jQuery plugin does is get the url for the thumbnail image - you can get a large or small image.
因为直到现在我还没有看到安迪的更新,所以我想出了一个......相当可怕的方法来做到这一点(但我接受了他的答案,因为它比我的好得多)。
与以下 html 配合使用:
我的解决方案从单击的图像中获取
#id
属性,然后将其插入到replaceWith()
代码中。它确实有效,不过是一种时尚。但截图->作物->至少可以说,另存为 video-id.png 的方法很乏味。我想我可能会保留我的解决方案 - 如果没有别的,作为一种可悲的自豪感 - 但我会尝试将其与 jYoutube 方法结合起来。如果这不起作用,那么我将使用安迪的答案。
As an update, I've adapted things to be a little more graceful, with jQuery's
animate()
:另外,我正在生成一个
x
,希望它可以提供服务,使用点击处理程序,将 Flash 视频对象缩小并替换为原始.png
。这是...如果我能弄清楚为什么 jQuery 不会让它有
$(this).click();
事件...有时我只是希望我知道何时停止..任何帮助表示感谢...=)
Because I didn't see the update from Andy 'til now, I came up with a...fairly horrible way to do this (but I accepted his answer, since it's so much nicer than mine).
Used in concert with the following html:
My solution, takes the
#id
attribute from the clicked image and then inserts that into thereplaceWith()
code. It works, after a fashion. But the screenshot -> crop -> save as video-id.png approach is tedious, to say the least. I think I'll probably keep my solution -as a matter of pathetic pride if nothing else- but I'll try and combine that with the jYoutube approach.If that doesn't work, then I'll be using Andy's answer.
As an update, I've adapted things to be a little more graceful, with jQuery's
animate()
:Also, I'm generating a
<span class="close"><a href="#">x</a></span>
, which hopefully should serve, with a click-handler, to shrink the flash video-object back down and replace it with the original.png
.This is...if I can work out why jQuery won't let it have a
$(this).click();
event...Sometimes I just wish I knew when to stop... any help is appreciated... =)