javascript - 从数据库检索图像并显示,以及如何使该图像在窗口中弹出以获得清晰的可见性。

标签 javascript php jquery html mysql

我必须从 MYSql 数据库检索图像并显示。显示数据库中的图像后,一旦我将鼠标悬停在网页上已有的图像上,则必须出现在清晰可见的弹出窗口中。 以下是我的检索代码。

<table align=center class="table table-bordered table-striped table-responsive">
<tr><th>Address Proof</th><th>Aadhar Card</th><th>Cast Certificate</th></tr><tr><td>
  <div style="float:left"><?php echo '<img style="padding:5px;" height="400" width="200" src="data:image; base64,'.$row[0].' ">';?></div></td><td>
 <div style="float:left"><?php echo '<img style="padding:5px;" height="400" width="200" src="data:image; base64,'.$row[1].' ">';?></div></td><td>
  <div style="float:left"><?php echo '<img style="padding:5px;" height="400" width="200" src="data:image; base64,'.$row[2].' ">';?></div></td>
</tr>
</table>

以下是从数据库检索到的图像。

谢谢你..

enter image description here

最佳答案

您可以使用图像的模态弹出 onclick

HTML

<!-- Trigger the Modal -->
<img id="myImg" src="/image/XWcU8.png" alt="Image" width="300" height="200">

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- The Close Button -->
  <span class="close" onclick="document.getElementById('myModal').style.display='none'">&times;</span>

  <!-- Modal Content (The Image) -->
  <img class="modal-content" id="img01">

  <!-- Modal Caption (Image Text) -->
  <div id="caption"></div>
</div>

CSS:

/* Style the Image Used to Trigger the Modal */
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (Image) */
.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image (Image Text) - Same Width as the Image */
#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation - Zoom in the Modal */
.modal-content, #caption { 
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)} 
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)} 
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

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

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}

JS:

// Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}

检查 JS FIDDLE 中的工作示例在这里。

                        **OR**

您可以使用 jQuery 在悬停时显示缩放图像。

HTML:

<img src="/image/XWcU8.png" width="250px" id="sidebar">

<div class="img"><img src="/image/XWcU8.png" width="400px" height="250px" id="img">
    </div>

JQUERY:(3.2.1 用于 fiddle ,您可以在下面找到)

$('#img').hide(); 
$('#sidebar').mouseover(function () {
      $('#img').show();      
});
$('#sidebar').mouseout(function () {
      $('#img').hide();      
});

查找 JS FIDDLE工作样本here

关于javascript - 从数据库检索图像并显示,以及如何使该图像在窗口中弹出以获得清晰的可见性。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43841501/

相关文章:

javascript - jQuery:打印嵌套数组中多个键的所有值

Php递归方法获取产品

JQuery 从远程站点加载内容

javascript - 将 Java 变量值存储到 JavaScript/jQuery 变量中

javascript - Jquery 立即向下滚动到一个类

javascript - 工厂的 AngularJS 本地存储

javascript - Google Apps 脚本 - 将 UrlFetch 响应转换为数组

javascript - 如何映射每个对象值都有唯一 id 的对象并将这些值返回到 React 组件

php - Symfony2 路由 : Two optional parameters - at least one required

php - 在 php 脚本完成之前通过 jquery load() 函数从 php 脚本获取结果