Opening a YouTube video in a lightbox or something on page load
My client wants a YouTube video (embeded object) to popup when a user comes to their site.
Does anyone know how it do this and what to use. It should be a lightbox or shadowbox, something that'开发者_JAVA百科s not a popup.
The video should run automatically and ideally close when it's over. Maybe I can specify a time until auto-close or something?
Please help. Thanks all!
This is a full working solution. Just copy this html. Don't forget to change the path to the js and css.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<script type="text/javascript">
$(document).ready(function() {
$("#yt").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 680,
'height' : 495,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
});
$('#foo').bind('click', function() {
alert($(this).text());
});
$('#foo').trigger('click');
</script>
</head>
<body onload='$("#yt").trigger("click");'>
<h1>fancybox example</h1>
<p><a id="yt" title="" href="http://www.youtube.com/watch?v=2y8G7wMgIPY&fs=1&autoplay=1"></a></p>
</body>
</html>
May you use a fancybox ?
Here is a link for it - http://fancybox.net/api
<script type="text/javascript">
$(document).ready(function() {
$("#trigger").fancybox().trigger('click');
});
</script>
Put your link #trigger somewhere in your document and hide it using css.
EDIT
<!DOCTYPE html>
<html>
<head>
<!-- Css -->
<link href="/path/to/fancybox.css" rel="stylesheet" type="text/css" />
<!-- Javascript -->
<script src="/path/to/jquery.js" type="text/javascript"></script>
<script src="/path/to/fancybox.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#trigger").fancybox().trigger('click');
});
</script>
</head>
<body>
<!--hide trigger using display:none -->
<p style="display:none"><a href="path/to/youtube" id="trigger"></a></p>
</body>
</html>
Here is the howto: http://fancybox.net/howto
You can use the boom-lightbox for free. it is pure javascript, super light weight and doesn't require jquery. show responsive content, youtube videos, etc.
https://github.com/boominteractive/boom-lightbox
精彩评论