javascript - 如何避免 div 动画形式落后于相关 div?

标签 javascript jquery html css

我有一些 div 可以扩展它们包含的图像以调整到更大的尺寸……悬停时。但是,当我这样做时,它们会落后于相关的 div。我提供了 gyazo gif,这是代码。

提前感谢任何可以提供帮助的人。我确实尝试过弄乱 z-index 但我没有运气。

https://gyazo.com/13aabe5ecb2763a64f3c215fe207b05a?token=83f00c7326c06866638fdd590f78b9ea

	$(document).ready(function(){
		
		$(".temp_thumb_1").mouseenter(function(){	
			
			
			$("#template_2_wrapper").css({
				"opacity" : '0'
			});
			
			$("#template_1_wrapper").animate({
				"width" : '628px',
				"height" : 'auto'
			});
					
			$(".temp_thumb_1").animate({
				"width" : '628px',
				"height" : 'auto'
			});
			
		});		
		
		$(".temp_thumb_1").mouseleave(function(){
			
			$("#template_1_wrapper").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
			$(".temp_thumb_1").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
		});
		
		
		$(".temp_thumb_2").mouseenter(function(){
			
			$("#template_2_wrapper").animate({
				"width" : '628px',
				"height" : 'auto'
			});
					
			$(".temp_thumb_2").animate({
				"width" : '628px',
				"height" : 'auto'
			});
		
			
		});		
		
		$(".temp_thumb_2").mouseleave(function(){
			
			$("#template_2_wrapper").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
			$(".temp_thumb_2").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
		});
		
		
			$(".temp_thumb_3").mouseenter(function(){
			
			$("#template_3_wrapper").animate({
				"width" : '628px',
				"height" : 'auto'
			});
					
			$(".temp_thumb_3").animate({
				"width" : '628px',
				"height" : 'auto'
			});
		
			
		});		
		
		$(".temp_thumb_3").mouseleave(function(){
			
			$("#template_3_wrapper").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
			$(".temp_thumb_3").animate({
				"width" : '157px',
				"height" : 'auto'
			});
			
		});
		
	});
	
#templates_sec_1{
	width:76%;
	margin:0 auto;
	background-color:#d7d7d7;
	height:200px;
}

#template_1_display, #template_2_display, #template_3_display{
	width:157px;
	height:100px;
    background-repeat: no-repeat;
    background-size: contain, cover;
	margin:0 auto;
}
	


#template_1_text_wrapper{
	height:100px;
	width:100%;
	background-color:white;
}

#template_1_hover, #template_2_hover, #template_3_hover{
	width:157px;
	height:200px;
	float:left;
}

.temp_thumb_1, .temp_thumb_2, .temp_thumb_3{
	width:157px;
	height:auto;
}

#template_1_text{
	height:100px;
	width:157px;
	background-color:white;
<div id='templates_sec_1'>
	<div id='template_1_hover'>
			<div id='template_1_display'>
				<a href=''><img src='images/template_1_thumbnail.png' class='temp_thumb_1'></a>
			</div>
			<div id='template_1_text'>
			</div>
	</div>
	<div id='template_2_hover'>
			<div id='template_2_display'>
				<a href=''><img src='images/template_2_thumbnail.png' class='temp_thumb_2'></a>
			</div>
			<div id='template_1_text'>
			</div>
	</div>	
	<div id='template_3_hover'>
			<div id='template_3_display'>
				<a href=''><img src='images/template_1_thumbnail.png' class='temp_thumb_3'></a>
			</div>
			<div id='template_1_text'>
			</div>
	</div>
</div>

最佳答案

Z-index 不起作用,因为您的问题在于模板的定位方式,您可以看出这一点,因为只有右侧的元素被放置在正在放大的元素之上。

您应该从所有元素中删除“float:left”。然后通过给模板的父元素“display:inline-flex”定位模板

关于javascript - 如何避免 div 动画形式落后于相关 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50193776/

相关文章:

javascript - 不安全的 JavaScript 尝试使用 URL 启动框架导航

javascript - 使用 ImmutableJS 更新映射列表中的一个键

javascript - ReactJS + D3 : Parse local CSV file and passing it to state with d3-request

javascript - 我可以使用 CSS 指定要使用选择器设置的类吗?

javascript - 如何在 Javascript 中更改关键帧状态

javascript - 使用 onkeypress 检测向上箭头被按下(HTML 和 Javascript)

javascript - 了解 Javascript 如何全局解析变量

javascript - 为什么这个基于短路求值的 if 语句不起作用?

jquery - 如何使用 jQuery 使图像或列表项变灰,但使图像或列表项保持可点击状态?

javascript - 在我的网络应用程序的固定侧按钮上悬停/单击不匹配?