简体   繁体   English

我的弹出式图片在我的测试项目中无法正常工作

[英]My popup image isn't working, while it is working in my test project

So for my internship I want to make a popup img . 因此,对于我的实习,我想制作一个弹出式img so when i click on an image the img pops up larger with a background and opacity. 因此,当我单击图像时,带有背景和不透明度的img更大地弹出。 I already have the code but it isn't working. 我已经有了代码,但无法正常工作。 btw don't mind the .grafisch-centrum class. 顺便说一句,不要介意.grafisch-centrum类。 it's included somewhere. 它包含在某个地方。

Here's my html 这是我的HTML

<img alt="Briefpapier drukken" class="resrc Gallery__FeaturedImg js-gallery-featured" data-src="https://s3-eu-west-1.amazonaws.com/printdealcdn/content_service/Briefpapier/briefpapier-drukken.png"
    id="changingImg" src="https://s3-eu-west-1.amazonaws.com/printdealcdn/content_service/Briefpapier/briefpapier-drukken.png"
    style="height: 300px !important; width: 300px !important;" />
</div>

<div class="popup" id="popup">
    <img class="popup-img" id="popup-img" />
    <span class="close">&times;</span>
</div>

Here's my css 这是我的CSS

.grafisch-centrum .popup{
    display: none;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0,0.9);
}
.grafisch-centrum .close{
    cursor: pointer;
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.grafisch-centrum .close:hover,
.grafisch-centrum .close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

.popup-img{
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

my javascript 我的JavaScript

var popup = document.getElementById('popup');
var img = document.getElementById('changingImg');
var popupImg = document.getElementById('popup-img');

img.onclick = function () {
    popup.style.display = 'block';
    popupImg.src = this.src;
}

var close = document.getElementsByClassName("close")[0];

span.onclick = function () {
    popup.style.display = 'none';
}

You have the following event: 您有以下事件:

span.onclick = function () {
  popup.style.display = 'none';
} // <-- also this closing bracket was missing from your example

But span is not declared 但是没有声明span

https://jsfiddle.net/zuuajgnk/ https://jsfiddle.net/zuuajgnk/

if you open your browser's console you'll see the following error: 如果打开浏览器的控制台,则会看到以下错误:

Uncaught ReferenceError: span is not defined 未捕获的ReferenceError:跨度未定义

otherwise, your image does get larger on click 否则,您的图片在点击时确实会变大

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM