Javascript查看大圖功能代碼實現(xiàn)
功能與實現(xiàn)
點擊小圖片可以查看大圖
實現(xiàn)就是把大圖放置在頂層(z-index大于當(dāng)前頁面的),并且還可以加一些額外的比如透明度什么的。
大圖以動畫的形式出現(xiàn)
動畫就是css動畫樣式了,可以自定義動畫,將圖片一點點變大,發(fā)揮想象了。
代碼
html代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style.css" rel="external nofollow" type="text/css">
<link rel="stylesheet" rel="external nofollow" >
</head>
<body>
<div class="row">
<div class="col" onclick="open_container(1)">
<img src="img/1.jpg" class="img">
</div>
<div class="col" onclick="open_container(2)">
<img src="img/2.jpg" class="img">
</div>
<div class="col" onclick="open_container(3)">
<img src="img/3.jpg" class="img">
</div>
<div class="col" onclick="open_container(4)">
<img src="img/4.jpg" class="img">
</div>
</div>
<div class="container" id="container">
<div class="close" id="close" onclick="close_container()">
<i class="fa fa-close" style="font-size:130px;color:white;"></i>
</div>
<div class="container_content">
<img id="content_img" class="content_img" src="img/1.jpg">
</div>
</div>
</body>
<script type="text/javascript" src="show.js"></script>
</html>
css代碼
.row{
margin:auto;
}
.row:after {
content: "";
display: table;
clear: both;
}
.col{
float: left;
width: 20%;
}
img {
margin-bottom: -4px;
width:100%;
height: auto;
}
.close{
position:absolute;
top:30px;
right:30px;
}
.container{
display:none;
position:fixed;
z-index:1;/*設(shè)置層疊順序:擁有更高堆疊順序的元素總是會處于堆疊順序較低的元素的前面*/
padding-top:100px;/*放置關(guān)閉按鈕*/
left:0px;
top:0px;
width: 100%;
height:100%;
overflow: auto; /*--溢出的情況*/
opacity:0.85;/*透明*/
background-color: black;
}
.container_content{
position: relative;
background-color: black;
margin: auto;
width: 90%;
max-width: 1200px;
}
.content_img{
width:150%;
height: auto;
-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)}
}
js代碼
function open_container(x){
document.getElementById("container").style.display="block";
var str="";
str="img/"+x+".jpg";
document.getElementById("content_img").src=str;
}
function close_container(){
document.getElementById("container").style.display="none";
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解析JavaScript實現(xiàn)DDoS攻擊原理與保護措施
本文主要對JavaScript實現(xiàn)DDoS攻擊原理與保護措施進行介紹,具有一定的參考價值,需要的朋友一起來看下吧2016-12-12
JavaScript實現(xiàn)的商品搶購倒計時功能示例
這篇文章主要介紹了JavaScript實現(xiàn)的商品搶購倒計時功能,可實現(xiàn)分秒級別的實時顯示倒計時效果,涉及js日期時間計算與頁面元素動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-04-04
TypeScript與JavaScript多方面闡述對比相同點和區(qū)別
TypeScript和JavaScript在開發(fā)交互式網(wǎng)頁方面有許多相似之處,在提供TypeScript與 JavaScript的直接比較時,我們可以說JavaScript是一種輕量級的解釋型動態(tài)語言,用于增強HTML網(wǎng)頁,TypeScript是JavaScript的增強版,這意味著TypeScript是JavaScript和其他一些特性的組合2024-07-07
JavaScript中檢測數(shù)組的3種方法小結(jié)
數(shù)組檢測是指在編程中對數(shù)組進行驗證和檢查的過程,本文主要介紹了JavaScript中檢測數(shù)組的3種方法小結(jié),具有一定的參考價值,感興趣的可以了解一下2023-08-08
JavaScript操作XML實例代碼(獲取新聞標(biāo)題并分頁,并分頁)
XML 代碼部分 這是一個新聞的XML 文件,如果 NBody部分包含 XML 和Html 不可識別部分, 就 包含在DATA 表示附中。2010-05-05
小程序?qū)崿F(xiàn)頁面跳轉(zhuǎn)與數(shù)據(jù)傳遞方案
在開發(fā)過程中經(jīng)常會遇到在微信小程序的頁面跳轉(zhuǎn)以及數(shù)據(jù)傳遞的知識點,所以下面這篇文章主要給大家介紹了關(guān)于小程序?qū)崿F(xiàn)頁面跳轉(zhuǎn)與數(shù)據(jù)傳遞的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-09-09
Javascript 實現(xiàn)TreeView CheckBox全選效果
Javascript 實現(xiàn)TreeView CheckBox 選中父節(jié)點時所有子節(jié)點全選,取消時全部取消2010-01-01

