其实弹出层的思路还是比较简单的:
一般是这个层是隐藏的(display:none),然后点击你说的"图片(或者任何的页面元素)",这个层就会显示(一般display:inline-block/block),同时设置一个灰色的背景看起来这个层是浮于下面的层之上的。
下面是一段演示代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8"><title>弹出层—到浏览器中央—背景变暗</title>
<style>
*{margin:0padding:0px}
body{padding:30px}
#show{width:300pxheight:200pxdisplay:nonepadding:1pxposition:absoluteborder:1px solid #4c77aabackground:#f2f7fdz-index:11zoom:1}
#show h3{background:#4c77aacolor:#ffffont-size:14pxpadding:5px}
#show span{position:absoluteright:3pxtop:3pxdisplay:blockcursor:pointercolor:#ffffont-weight:bold}
#show p{padding:5px}
#text{font-size:12pxtext-indent:2emline-height:20px}
#bgbox{position:absoluteleft:0top:0background:#000filter:alpha(opacity=30)opacity:0.3z-index:10}
</style>
<script type="text/javascript">
function show(){
var iWidth = document.documentElement.clientWidth
var iHeight = document.documentElement.clientHeight
var bgObj = document.createElement("div")
bgObj.setAttribute("id","bgbox")
bgObj.style.width = iWidth+"px"
bgObj.style.height =Math.max(document.body.clientHeight, iHeight)+"px"
document.body.appendChild(bgObj)
var oShow = document.getElementById('show')
oShow.style.display = 'block'
oShow.style.left = (iWidth-302)/2+"px"
oShow.style.top = (iHeight-202)/2+"px"
function oClose(){
oShow.style.display = 'none'
document.body.removeChild(bgObj)
}
var oClosebtn = document.createElement("span")
oClosebtn.innerHTML = "×"
oShow.appendChild(oClosebtn)
oClosebtn.onclick = oClose
bgObj.onclick = oClose
}
</script>
</head>
<body>
<a onclick="show() return false" href="#">请猛击我(我会弹到中间,同时背景变暗)</a>
<div id="show"><h3>弹出层标题栏</h3>
<p id="text">
这里是弹出层内容,内容可以是文字、图片等,可以是iframe传进来,也可以用jQuery的load()传进来。
</p>
</div>
</body>
</html>
<style>.box {display:flexmargin:100px 100px}
.box img {position:relativeheight:200pxtransition:all 0.5sz-index:1box-shadow:0 0 1px #000}
</style>
<div class="box">
<img src="图片1"/><img src="图片2"/><img src="图片3"/><img src="图片4"/><img src="图片5"/>
</div>
<script type="text/javascript">
$(function(){
$(".box img").click(function(){
$(".box img").css({"transform":"scale(1,1)","z-index":"1","box-shadow":"0 0 1px #000"})
$(this).css({"transform":"scale(1.6,1.6)","z-index":"3","box-shadow":"0 0 10px #000"})
if($(this).prev())$(this).prev().css({"transform":"scale(1.3,1.3)","z-index":"2","box-shadow":"0 0 5px #000"})
if($(this).next())$(this).next().css({"transform":"scale(1.3,1.3)","z-index":"2","box-shadow":"0 0 5px #000"})
})
})
</script>
需要引用jquery
js 左侧无缝循环原理: 在float_left float_right外侧应该还有一层div,那层div的宽度必须是float_left的实际宽度的两倍,而float_left内的内容宽度不得小于float_left的规定宽度,否则也会出现断层或滚动停止