【发布时间】:2012-04-25 21:09:19
【问题描述】:
我有一组动态生成的图像(每张图像附近都有评论)。我想显示最大宽度和最大高度为 48 像素的每个图像,但是当用户将鼠标悬停在图像上时,它会增长到最大宽度和最大高度 200 像素。但无需移动页面上的其他所有内容。这是生成图像的代码:
$(function(){
$.getJSON("inc/API.php",
{command : "getUserComments", userid : getQueryStringValue("userid")},
function(result)
{
for (var i = 0; i<6; i++){
$("#divUserCommentsContent").append("<div id='divUserComment'><div id='divCommentTime'>"+
result[i].commentDateAndTime+"</div><div id='divUserDetail'><div id='divUserpic'>
**<img src='images/"+result[i].imageFileName+"' class='commentpic' />**</div>
<div id='divUsername'>Comment for <a href='rank.html?imageID="+result[i].imageID+
"&imageFileName="+result[i].imageFileName+"'>"+result[i].imageHeader+
"</a></div></div><div id='divCommentText'>"+result[i].comment+"</div></div>");
}
});
});
我用 2 ** 标记了图像。这是 CSS:
.userpic, .commentpic
{
max-height:48px;
max-width:48px;
border-radius:5px;
z-index:1;
position:relative;
}
.commentpic:hover
{
max-width: 200px;
max-height: 200px;
position:relative;
z-index: 50;
}
它会放大图像,但也会移动图像右侧和图像下方的所有其他内容。
如何在不移动其他所有内容的情况下使用 CSS(最好)或使用 jQuery 使图像更大?谢谢!
【问题讨论】:
-
z-index 工作吗?
-
@DotNetter 是的,很像,甚至可能是这样的:http://host.sonspring.com/hoverbox/
-
@AnishGupta 我在这里使用 z-index。我试图将
z-index:0;放在其他元素上,但这并没有帮助,它们仍在移动...... -
@Igal 你有职位吗?
标签: jquery css image image-enlarge