Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup to show youtube video inside iframe [closed]

Please, help me realize this function!

When clicked, a popup container, where load title and iframe (video from Youtube).
Any ideas?
Maybe there are plugins?

<a id="popup" href=""></a>

<a id="popup" href=""></a>


<div id="video-view">
     <h1>title</h3>
     <iframe ... ></iframe> 
</div>

P.S. Sorry for my English =) enter image description here

like image 689
Dmitry Avatar asked Jan 29 '14 06:01

Dmitry


2 Answers

HTML

<a class="popup" href="#!" data-link="http://www.youtube.com/embed/fbVD32w1oTo?enablejsapi=1" data-title="How to install SASS">SASS</a>

<a class="popup" href="#!" data-link="http://www.youtube.com/embed/Q0HFBy2BtfA?enablejsapi=1" data-title="How to install Node.js">Node.js</a>


<div id="video-view">
</div>

JQuery

$(".popup").click(function () {
    var $this = $(this);
    var $iframe = $("<iframe>").attr("src", $this.data("link")).css({"width": 400, "height": 300});
    var $title = $("<h1>").text($this.data("title"));
    $("#video-view").html($title).append($iframe);
    $iframe.wrap("<div class='class-video'>");
});

JSFiddle

http://jsfiddle.net/ergec/BrW5w/

like image 121
Ergec Avatar answered Oct 04 '22 00:10

Ergec


Expanding on @Eregec answer to make the video show up in a popup.

HTML

<div class="page">
    <p><a href="#media-popup" data-media="//www.youtube.com/embed/YoXa2Pl7Hk0">click me</a></p>

    <div class="popup" id="media-popup">
        <iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

CSS

html,
body {
    margin:0; padding:0; height:100%;
}
p {
    margin:0;
}
.page {
    position: relative;
    height:100%;
}

.popup {
    position:absolute;
    z-index:2;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background:rgba(0,0,0,0.7);
    opacity:0;
    visibility:hidden;
    transition:.3s ease;
}

.show-popup .popup {
    opacity:1;
    visibility: visible;    
}

.popup > iframe {
    position:absolute;
    top:50px;
    left:50%;
    margin-left:-280px;
}

JS

$("[data-media]").on("click", function(e) {
    e.preventDefault();
    var $this = $(this);
    var videoUrl = $this.attr("data-media");
    var popup = $this.attr("href");
    var $popupIframe = $(popup).find("iframe");

    $popupIframe.attr("src", videoUrl);

    $this.closest(".page").addClass("show-popup");
});

$(".popup").on("click", function(e) {
    e.preventDefault();
    e.stopPropagation();

    $(".page").removeClass("show-popup");
});

$(".popup > iframe").on("click", function(e) {
    e.stopPropagation();
});

JS Fiddle

like image 35
Varinder Avatar answered Oct 04 '22 00:10

Varinder