标签:function src style image large 点击 html5 display 放大
第一种:
css:<style type="text/css">
*
{
margin:0px;
padding:0px;
}
.zhezhao
{
width:100%;
height:100%;
background-color:#000;
filter:alpha(opacity=50);
-moz-opacity:0.5;
opacity:0.8;
position:absolute;
left:0px;
top:0px;
display:none;
z-index:4;
}
</style>
html:
<div class="zhezhao" id="zhezhao" onclick="bg();"></div>
<div class="image_large" onclick="hideImg();" hidden>
</div>
<img src='"+data.userHead+"' onclick="imgshow('" + data.userHead + "');" height='30px' class="logoImg amplifyImg"/>
<script type="text/javascript">
var zhezhao=document.getElementById("zhezhao");
var login=document.getElementById("login");
function imgshow(src){
var large_image = '<img src= '+ src +'></img>';
$('.image_large').show();
$('.image_large').html($(large_image).attr("style","display:block;height:90%;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);z-index:5;"));
zhezhao.style.display="block";
login.style.display="block";
}
function hideImg() {
$('.image_large').hide();
zhezhao.style.display="none";
login.style.display="none";
}
function bg() {
$('.image_large').hide();
zhezhao.style.display="none";
login.style.display="none";
}
</script>
第二种:
1.html 代码
<div id="imgEnlargeDiv" style="display: none; text-align: center;position: fixed;z-index: 1000;top: 0;left: 0;
width: 100%;height: 100%;background-color: rgba(255,255,255,.9);">
<img id="bigimg" style="height: auto;width: 40%;border: 0;
margin: auto;position: absolute;top: 0;bottom: 0;left: 0;right: 0;" src="" />
</div>
2.js 代码
<script src="assets/js/jquery-1.10.2.min.js"></script> <!--引入jquery -->
<script type="text/javascript">
//图片放大
$(function(){
$("#imgEnlargeDiv").click(function(){//再次点击淡出消失弹出层
$(this).fadeOut("fast");
});
});
function imgShow(outerdiv, bigimg, _this){
var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
$(bigimg).attr("src", src);//设置#bigimg元素的src属性
$(outerdiv).fadeIn("fast"); //图片放大的div快速淡入显示层
}
function imgEnlarge() {
$("img[type ='showImg']").mouseover(function(){
$(this).css("cursor","pointer");//鼠标移动到图片,鼠标箭头变为手势
});
$("img[type ='showImg']").click(function(){
var _this = $(this);//将当前的pimg元素作为_this传入函数
imgShow("#imgEnlargeDiv", "#bigimg", _this);
});
}
</script>
3.使用
调用imgEnlarge(); 则会对$("img[type ='showImg']")的图片添加点击事件。
点击图片后则会弹出图片放大层。
标签:function,src,style,image,large,点击,html5,display,放大 来源: https://blog.csdn.net/pengxiaozhong/article/details/121272575
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。