2014-09-25 79 views
1

我想爲圖庫做懸停圖像。當用戶將鼠標懸停在圖像上時,它會在頁面中間以固定位置彈出,但現有圖像(縮略圖)仍保持原位。懸停圖像顯示在頁面中間和縮略圖停留

但是,不知道我做錯了懸停圖像在圖像本身,而不是主頁。

我隱藏了另一張爲主頁面彈出的圖像,因此頁面中的縮略圖將保持原樣。但是,此圖像正在縮略圖中盤旋。

Demo

body { 
     margin: 0; 
     padding: 0; 
     background: #EEE; 
     font: 10px/13px 'Lucida Sans',sans-serif; 
    } 

.wrap { 
     overflow: hidden; 
     margin: 50px; 
    } 

/*20 for 5 box , 25 for 4 box*/ 
.box { 
     float: left; 
     position: relative; 
     width: 25%; 
     padding-bottom: 25%; 
     color: #FFF; 


    } 
    /*border width control*/ 
.boxInner { 
     position: absolute; 
     left: 30px; 
     right: 30px; 
     top: 30px; 
     bottom: 30px; 
     overflow: hidden; 
     background: #66F; 

    } 

.boxInner img { 
     width: 100%; 
    } 





.gallerycontainer{ 
position: relative; 
/*Add a height attribute and set to largest image's height to prevent overlaying*/ 
} 





/*This hover is for small image*/ 
.thumbnail:hover img{ 
border: 1px solid transparent; 
} 

/*This hide the image that is in the span*/ 
.thumbnail span{ 
position: absolute; 
padding: 5px; 
visibility: hidden; 
color: black; 
text-decoration: none; 
} 

/*This is for the hidden images, to resize*/ 
.thumbnail span img{ /*CSS for enlarged image*/ 
border-width: 0; 
width:200%; /* you can use % */ 
height: auto; 
padding: 2px; 
} 

/*When mouse over, the hidden image apear*/ 
.thumbnail:hover span{ 
position:absolute; 
visibility: visible; 
top: 0; 
left: 0; 
z-index: 200; 
} 
+0

變化'位置:絕對;''到的位置是:固定的;'上.thumbnail懸停狀態。 – Fergoso 2014-09-25 03:26:15

回答

1

它的位置改變到absolutefixed,這就是爲什麼它被由家長span裁剪。如果您將其更改爲fixed,它應該可以工作。因此,改變這種情況,

.thumbnail:hover span{ 
position:absolute; 
visibility: visible; 
top: 0; 
left: 0; 
z-index: 200; 
} 

這個

.thumbnail:hover span{ 
position:fixed; 
visibility: visible; 
top: 0; 
left: 0; 
z-index: 200; 
} 

你可能要調整,雖然一些其他屬性,如width,所以它並不需要200%關閉頁面

這裏有一個JS Fiddler Example,我在其中添加了以下css聲明

.thumbnail:hover span{ 
position:fixed; 
visibility: visible; 
    max-width:600px; 
top: 0; 
left: 0; 
z-index: 200; 
    left:25%; 
    top:25%; 
} 

.thumbnail:hover span img{ 
    width:100%; 
} 
0

更換

.thumbnail:hover span{ 
position:absolute; 
visibility: visible; 
top: 0; 
left: 0; 
z-index: 200; 
} 

.thumbnail:hover span{ 
    position:fixed; 
    visibility: visible; 
    max-width:600px; 
    top: 0; 
    left: 0; 
    right:0; 
    bottom:0; 
    margin: auto; 
    z-index: 200; 
} 
0

嘗試。

body { 
 
    margin: 0; 
 
    padding: 0; 
 
    background: #EEE; 
 
    font: 10px/13px'Lucida Sans', sans-serif; 
 
} 
 
.wrap { 
 
    overflow: hidden; 
 
    margin: 50px; 
 
} 
 
/*20 for 5 box , 25 for 4 box*/ 
 
.box { 
 
    float: left; 
 
    position: relative; 
 
    width: 25%; 
 
    padding-bottom: 25%; 
 
    color: #FFF; 
 
} 
 
/*border width control*/ 
 
.boxInner { 
 
    position: absolute; 
 
    left: 30px; 
 
    right: 30px; 
 
    top: 30px; 
 
    bottom: 30px; 
 
    overflow: hidden; 
 
    background: #66F; 
 
} 
 
.boxInner img { 
 
    width: 100%; 
 
} 
 
.gallerycontainer { 
 
    position: relative; 
 
    /*Add a height attribute and set to largest image's height to prevent overlaying*/ 
 
} 
 
/*This hover is for small image*/ 
 
.thumbnail:hover img { 
 
    border: 1px solid transparent; 
 
} 
 
/*This hide the image that is in the span*/ 
 
.thumbnail span { 
 
    position: absolute; 
 
    padding: 5px; 
 
    visibility: hidden; 
 
    color: black; 
 
    text-decoration: none; 
 
} 
 
/*This is for the hidden images, to resize*/ 
 
.thumbnail span img { 
 
    /*CSS for enlarged image*/ 
 
    border-width: 0; 
 
    width: 200%; 
 
    /* you can use % */ 
 
    height: auto; 
 
    padding: 2px; 
 
} 
 
/*When mouse over, the hidden image apear*/ 
 
.thumbnail:hover span { 
 
    position: fixed; 
 
    visibility: visible; 
 
    z-index: 200; 
 
    zoom: 62%; 
 
    bottom: 0; 
 
    right: 0; 
 
} 
 
.thumbnail:hover span img { 
 
    width: 100%; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<link href="overlay2.css" rel="stylesheet" type="text/css" /> 
 

 
<head> 
 
    <title>Test</title> 
 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
 
    <meta name="description" content="" /> 
 
    <meta name="keywords" content="" /> 
 
</head> 
 

 

 
<body> 
 

 

 
    <div class="wrap"> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/7.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/7.jpg" /></span> 
 
     </a> 
 

 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/6.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/6.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/1.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/1.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/2.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/2.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/3.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/3.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/4.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/4.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 
    <div class="box"> 
 
     <div class="boxInner"> 
 
     <a class="thumbnail" href="#"> 
 
      <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/8.jpg" /><span><img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/8.jpg" /></span> 
 
     </a> 
 
     </div> 
 
    </div> 
 

 

 

 

 
    </div> 
 

 

 
</body> 
 

 
</html>