【问题标题】:How to open a clicked video block to a pop modal?如何将点击的视频块打开到弹出模式?
【发布时间】:2019-06-19 21:05:05
【问题描述】:

我有一个侧边栏,它显示来自 JSON 文件的电影列表,这里是它的外观。

现在我希望当用户单击列表中某部电影的编辑按钮时,它应该打开一个带有电影块的弹出模式,类似于这样。

这里是现场演示 jsfiddle:live demo

这是我迄今为止尝试过的

HTML

<ul class="sidebar">
</ul>

<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <span class="close">&times;</span>
    </div>

</div>

这里是js

$(function() {
        var movies = [{
                        "title": "travel",
                        "left": 201,
                        "top": 209,
                        "movieid": "10",
                        "movie_url": "http://techslides.com/demos/sample-videos/small.mp4",
                        "buttons": [{
                                "left": 81,
                                "top": 51,
                                "start_time": 1,
                                "end_time": 2,
                                "buttonid": "10_1",
                                "btn_url": "http://techslides.com/demos/sample-videos/small.mp4"
                        }]
                },
                {
                        "title": "ecommerce",
                        "movieid": "20",
                        "movie_url": "http://techslides.com/demos/sample-videos/small.mp4",
                        "buttons": [{
                                "left": 0,
                                "top": 0,
                                "start_time": 1,
                                "end_time": 2,
                                "width": '200',
                                "height": '60',
                                "buttonid": "20_1",
                        }]
                }
        ];

        function formatTitle(t) {
                var nt = t[0].toUpperCase();
                nt += t.slice(1);
                return nt;
        }

        function makeListItem(v, p) {
                var li = $("<div id='" + v.movieid + "' class='sidebar_movie-block'>");
                var title = $("<h1>", {
                        class: "title",
                        for: "video_" + v.movieid
                }).html(formatTitle(v.title)).appendTo(li);

                var edit = $("<span>", {
                        class: "block-edit fa fa-edit",
                        for: "video_" + v.movieid,

                }).appendTo(li);
                var vObj = $("<video>", {
                        id: "video_" + v.movieid,
                        src: v.movie_url
                }).appendTo(li);
                li.appendTo(p);
        }

        function getVideoList() {
                $.each(movies, function(index, dataValue) {
                        makeListItem(dataValue, $(".sidebar"));
                });
        }

        getVideoList();



        var modal = $("#myModal");

        // When the user clicks the button, open the modal 
        $(".block-edit").on("click", function() {
                $("#myModal").css("display", "flex");

        })

        // When the user clicks on <span> (x), close the modal
        $(".close").on("click", function() {
                $("#myModal").css("display", "none");
        })

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
                if (event.target == modal) {
                        modal.style.display = "none";
                }
        }

});

单击编辑后,我被困在弹出模式中显示电影,我尝试了不同的方法,但不幸的是我没有想法。

我需要改变什么才能得到我想要的?任何建议或帮助将不胜感激

【问题讨论】:

  • 您可以考虑使用 jQuery UI Dialog 来包含电影项并使用它的 Modal。

标签: javascript jquery html json html5-video


【解决方案1】:

对不起布局,但我所做的只是添加一个名为“modalVideo”的模态关闭按钮的兄弟元素和另一个名为“modalTitle”的标题:

<ul class="sidebar">
</ul>
<div id="myModal" class="modal">
   <!-- Modal content -->
   <div class="modal-content">
        <h1 id="modalTitle"></h1>
        <span class="close">&times;</span>
        <div id="modalVideo">
        </div>
   </div>                              
</div>

我添加了这个功能,在点击视频时触发,添加到modal中。

$("video").on("click", function(cls){
    $("#myModal").css("display", "flex");
    //get video tag and put into modal.
    $("#modalVideo")[0].innerHTML = cls.target.outerHTML
})

如果你想切换到点击按钮,只需将$("video")更改为 想要的元素。

这里是提琴手链接:https://jsfiddle.net/z4v18y3g/

[编辑]

新的提琴手,标题:https://jsfiddle.net/z4v18y3g/2/

【讨论】:

  • 嗨达米安,当我测试你的小提琴时,它只显示视频,标题怎么样?
  • 哦,等一下
  • 试试这个jsfiddle.net/z4v18y3g/2 我在模态中添加了另一个div,称为“modalTitle”,如果它有效,请通知我,我会添加回答
  • 抱歉damian,当iChange选择器从$('视频')到$('.block-edit)显示只是模态没有视频和标题,只有在Selecto $('视频')时才有效,只能工作,:(这是链接jsfiddle.net/z4v18y3g/2
  • 这里是代码,我刚刚删除了“视频”事件,并在按钮点击事件中添加了一些代码,看看:jsfiddle.net/wksacnp9/1 抱歉缺少 cmets,我现在没有时间: /
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-09
  • 1970-01-01
  • 2017-07-09
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
相关资源
最近更新 更多