简体   繁体   English

鼠标悬停显示全尺寸图像

[英]On mouse hover show full size image

I have 2 links for the same image. 我有2个相同图像的链接。 One is a thumbnail which is being displayed on the screen. 一个是显示在屏幕上的缩略图。 The second link is the full size image of the thumbnail. 第二个链接是缩略图的完整大小图像。

How can I code this so that when the mouse hovers over the image the screen turns black and just the full screen image is shown? 如何编码,以便当鼠标悬停在图像上时,屏幕变黑,只显示全屏图像?

<div id= "1" class="thumbnail"><a href="/fullsizeimage.jpg"><img scr="/thumbnail.jpg"> </a></div>
<div id= "2" class="thumbnail"><a href="/fullsizeimage2.jpg"><img scr="/thumbnail2.jpg"> </a></div>

On mouse hover 在鼠标悬停

  1. Make screen black 使屏幕变黑
  2. Load Fullsizeimage.jpg in the centre of the screen 在屏幕中央加载Fullsizeimage.jpg

Well what you could possibly do is place a div element above all other elements (use 100% width and height, position:absolute and z-index ). 那么你可能做的是将div元素放在所有其他元素之上(使用100%宽度和高度, position:absolutez-index )。 Make it hidden by default. 默认情况下将其隐藏。 Then when you are ready to display an image, make that div visible and load the full size image into it. 然后,当您准备好显示图像时,使该div可见并将完整尺寸的图像加载到其中。 You can make the screen black simply by giving that div some css properties - background-color:black . 你可以简单地通过给div一些css属性 - background-color:black来使屏幕background-color:black

You'll want to modify your HTML to have the small image contain a reference to the large image. 您需要修改HTML以使小图像包含对大图像的引用。 Something like this - 像这样的东西 -

<div id= "smallImage" class="thumbnail"><a href="/fullsizeimage.jpg"><img scr="/thumbnail.jpg"> </a></div>

For the actual loading of the image, you'd want to do something like this - 对于图像的实际加载,你想要做这样的事情 -

$("#smallImage").on('mouseover',function(){
  var smallImage = $(this);
  var largeReference = smallImage.attr('rel');
  $("#largeImage").attr('src',largeReference);
});

Then the HMTL for the large image would be - 那么大图像的HMTL将是 -

<img id="largeImage" src="" />

Don't forget to allow the user to close this large image view. 不要忘记允许用户关闭此大图像视图。

Use the Below CSS to display black div on hover property of an image 使用Below CSS在图像的悬停属性上显示黑色div

`#1 Img:hover +div  {
position:fixed;
top:0px;
left:0px;
width:"set the width";
height :"set the height";
}`
function fullscreen1() {
img = document.getElementById('img1')
img.src = "/fullsizeimage.jpg"
img.style = "position:fixed;top:30px;left:30px;width:990px;box-shadow:6px 7px 5px;background-color:rgb(70,70,70);"}
 function fullscreen2() {
img = document.getElementById('img2')
img.src = "/fullsizeimage2.jpg"
img.style = "position:fixed;top:30px;left:30px;width:990px;box-shadow:6px 7px 5px;background-color:rgb(70,70,70);"}
    <div id= "1" class="thumbnail"><a href="/fullsizeimage.jpg" onmouseover="fullscreen1()"><img id="img1" scr="/thumbnail.jpg"> </a></div>
    <div id= "2" class="thumbnail"><a href="/fullsizeimage2.jpg" onmouseover="fullscreen2()"><img id="img2" scr="/thumbnail2.jpg"> </a></div>

dont forget to put the close link as suggested in one of the answers 别忘了按照其中一个答案中的建议放置关闭链接

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

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