简体   繁体   English

转换div时如何阻止兄弟姐妹移动?

[英]How do I stop siblings from moving when transforming div?

I'm working on a Javascript which scales a div, amongst other things, when hovered on. 我正在开发一个Javascript,当鼠标悬停时可缩放div。 The problem is that the siblings to that div move when it resizes. 问题在于,该div的兄弟姐妹在调整大小时会移动。 I understand why this happens, but I don't know how to stop it. 我知道为什么会发生这种情况,但我不知道如何阻止它。 I've tried to change the z-index but it doesn't stop the others from moving. 我试图更改z-index,但它不会阻止其他索引的移动。

$(".medarbetareObjekt").mouseenter(function () {
$(this.getElementsByTagName("address")[0]).css("display", "inline");
$(this).css("background-color", "#f2f2f2");
$(this).css("font-weight", "100");
$(this).css("z-index", "1000");
$(this).css("width", "40%");
$(this).css("border-radius", "10px");
$(this.getElementsByTagName("img")[0]).css("width", "80%");
$(this.getElementsByClassName("img-circle")[0]).css("margin-top", "5px");
}).mouseleave(function () {
$("address").css("display", "none");
$(this).css("background-color", "transparent");
$(this.getElementsByClassName("img-circle")[0]).css("margin-top", "0px");
$(".medarbetareObjekt").css("font-weight", "300");
$(this).css("z-index", "10");
$(this).css("width", "20%");
$(this).css("border", "none");
$(this.getElementsByTagName("img")[0]).css("width", "100%");
});

So to sum it all up, how do I resize a div without affecting other divs? 因此,总而言之,如何在不影响其他div的情况下调整div的大小?

https://jsfiddle.net/mellquist/58jmo1au/31/ https://jsfiddle.net/mellquist/58jmo1au/31/

I added this css.. 我添加了这个CSS。

.zoom {
  -webkit-transform:scale(2);
  -moz-transform:scale(2);
  transform:scale(2);
}

And modified your script to add with these lines .. 并修改您的脚本以添加这些行..

$(this).addClass("zoom") and $(this).removeClass("zoom") $(this).addClass("zoom")$(this).removeClass("zoom")

Plus I removed a lot of the transforms and such from both your script and css. 另外,我从脚本和CSS中删除了很多转换,例如。 In doing so I somehow remove the centering of your text below the images. 这样,我就以某种方式删除了图像下方的文本居中位置。 I will leave that to you to trouble shoot 我会留给你麻烦解决

here is an updated fiddle https://jsfiddle.net/pokd8jv9/2/ 这是更新的小提琴https://jsfiddle.net/pokd8jv9/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM