【问题标题】:How to zoom out image out of the html container如何从 html 容器中缩小图像
【发布时间】:2014-02-09 14:33:44
【问题描述】:

我在 html 页面正文中的 div 标签旁边有一个 html 表格。我在表的 td 元素之一中有一个图像。当我将鼠标悬停在 td 元素上的图像上时,我的要求是缩小图像(就像在大多数电子商务网站中一样)。

我找到了代码并且能够做到。但问题是它仅限于<td><div> 容器,并且不会缩小其他部分。

这是我的<td> 标签-

<td colspan="4"><img class ="blog" src="shirt.jpg" alt="Item" border='3' height='390' width='638'/></td>

这是 CSS -

.blog:hover {
    cursor: pointer;
    height:475px;
    width: 350px;
    transform:scale(1.5);
    -ms-transform:scale(1.5); /* IE 9 */
    -moz-transform:scale(1.5); /* Firefox */
    -webkit-transform:scale(1.5); /* Safari and Chrome */
    -o-transform:scale(1.5); /* Opera */
    overflow: auto;
}

截图here.

【问题讨论】:

  • 尝试为图片外的td元素设置overflow:auto。
  • 试过了。那没有帮助:(。.tdflow{ overflow: auto; }&lt;td colspan="4" class="tdflow"&gt;&lt;img class ="blog" src="
  • 您期望什么行为?图像是否应该越界?检查这个小提琴:jsfiddle.net/g3v4F/1
  • 这正是我需要的 Nix。但是 smhow 无法让它工作。也尝试使用 z 索引。 .blog:hover { cursor: pointer; height:475px; width: 350px; z-index:999; transform:scale(1.5); -ms-transform:scale(1.5); /* IE 9 */ -moz-transform:scale(1.5); /* Firefox */ -webkit-transform:scale(1.5); /* Safari and Chrome */ -o-transform:scale(1.5); /* Opera */ }
  • 已添加屏幕截图以获取更多详细信息。希望对您有所帮助。

标签: javascript jquery html css


【解决方案1】:

我会把这个提琴作为一个想法扔掉 - FIDDLE

我只是不确定您想要的功能。将鼠标悬停在某物上的概念是否可以看到更大的画面?

CSS

.photo img {
    width: 100px;
    height: 100px;
    transition: all 1s;
}
.holder {
    width: 200px;
    height: 200px;
    text-align: center;
    margin: 20px auto;
    position: relative;
}
.fixeddiv {
    width: 200px;
    height: 200px;
    border: 1px solid blue;
    display: none;
    position: absolute;
    top: 10px;
    left: 200px;
    transform:scale(1);
}
.photo:hover  .fixeddiv {
    display: block;
    }
.photo:hover  .fixeddiv img {
    display: block;
    width: 200px;
    height: 200px;
}

【讨论】:

  • 你说得对,蒂姆。这正是我所需要的。让我试试这个。
  • 如果您希望图像直接放大到悬停图像的顶部,则不需要支架。
  • 哦,好的。这是个好主意。我想知道使用 js 是否会提供更多功能。我会拉小提琴。
  • 这是一个使用 jquery 的小提琴,它提供了更多的“易于编码”。 jsfiddle.net/timspqr/vMh4R/1。您可以使用单个“放大” div,也可以在原始图像旁边弹出一个窗口。
【解决方案2】:

postion:absolute; 添加到.blog:hover

确保 img 的父级已设置其位置或绝对位置,以便图像不会显示在页面的某些不需要的部分。

.blog:hover {
    postion:absolute;
    top:0;
    left:0;
    cursor: pointer;
    height:475px;
    width: 350px;
    transform:scale(1.5);
    -ms-transform:scale(1.5); /* IE 9 */
    -moz-transform:scale(1.5); /* Firefox */
    -webkit-transform:scale(1.5); /* Safari and Chrome */
    -o-transform:scale(1.5); /* Opera */
    overflow: auto;
}

【讨论】:

  • 天知道是什么问题。它也没有帮助:(。.blog:hover { postion:absolute; cursor: pointer; height:475px; width: 350px; z-index:999; transform:scale(1.5); -ms-transform:scale(1.5); /* IE 9 */ -moz-transform:scale(1.5); /* Firefox */ -webkit-transform:scale(1.5); /* Safari and Chrome */ -o-transform:scale(1.5); /* Opera */ overflow: auto; } Parent TD .tdflow{ overflow: auto; postion:relative; } TD Parent DIV .contain div { background-color:666677; .. font: 10pt Arial,Helvetica; overflow:auto } .mpd1{..;position:absolute}
  • 由于某种原因,div 标签中的overflow: auto 导致了它。删除它并替换为z-index:999; 并且它有效:)。感谢您的帮助。点赞!!
  • 它被放大但不在顶部,即没有隐藏另一个 div 元素。有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
相关资源
最近更新 更多