我正在使用Angular 8创建一个带有物化的页面,在该页面中我需要显示一些图片,如果用户单击其中一张,我希望它以全屏模式打开,则物化有一个您可以执行的操作它,但是当我使用它时,图像无法打开 我希望它会在此链接中打开 https://materializecss.com/media.html 但这对我的点击没有任何反应 我试图这样做:
<img src="assets/img/test.png" class="materialboxed">
that's my html page
<div class="container ">
<h1>Materialize Image Gallery</h1>
<div class="row card">
<div class="col s12 m6 l4">
<img src="assets/img/test.png" class="materialboxed">
</div>
<div class="col s12 m6 l4">
<img src="assets/img/test1.png" class="materialboxed">
</div>
<div class="col s12 m6 l4">
<img src="assets/img/test2.png" class="materialboxed">
</div>
</div>
</div>
这是我的索引页
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test page</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link type="text/css" rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"
media="screen,projection">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<app-root></app-root>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"
type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</body>
</html>
答案 0 :(得分:0)
与摘要一样,您没有按照文档中的描述初始化MaterialBox小部件。
在索引文件中,使用此JQuery添加脚本:
$(document).ready(function(){
$('.materialboxed').materialbox();
});
或者您可以添加原始Javascript:
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.materialboxed');
var instances = M.Materialbox.init(elems, options);
});
使用JQuery的最终索引页文件应如下所示:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test page</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link type="text/css" rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"
media="screen,projection">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<app-root></app-root>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"
type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
//Added Code
$(document).ready(function(){
$('.materialboxed').materialbox();
//End Added Code
</script>
</body>
</html>
我希望这个答案可以帮助别人。