【发布时间】: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">×</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