【问题标题】:jQuery: slideDown and fade, loosing the height instantlyjQuery:slideDown和fade,立即失去高度
【发布时间】:2017-05-09 19:44:41
【问题描述】:

我希望同时淡入/淡出和滑上/滑下,以便平稳地下降或上升标题。

在此代码中,尝试悬停和悬停。悬停动作使标题Audi 立即下降。

$(document).ready(function(){
			$("#introgreen .col-md-4").hover(function(){
			    $(this).find('.imagep text').slideUp().fadeIn(800);			    
			    }, function(){
			    $(this).find('.imagep text').slideDown().fadeOut(800);			    
			});
			
		});
#introgreen img{
	width: 100%;
	position: relative;
}
#introgreen .col-md-4 .wholeimage{
	position: relative;
	width: 100%;
}
#introgreen .imagespan{
	position: absolute;
	left: 0;
	top: 20;
	background-color: #d24f0b;
	padding: 5px 15px;
	font-size: 18px;
	font-weight: bold;
	color: white;
	z-index: 3;
}
#introgreen .imagep{
	display: inline-block;
	border: solid 1px white;
	position: absolute;
	width: 100%;
	left: 0;
	bottom: 0;
	color: white;
	background-color: rgba(0,0,0,0.5);
	height: auto;
	padding: 20px;
}

.imagep text{
    display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<div id="introgreen">
<div class="col-md-4"><div class="wholeimage"><img src="http://autopazar.co.uk/media/5215/Used_Audi_Q7_2007_Black_4x4_Diesel_Automatic_for_Sale_in_Kent_UK.jpg"><span class="imagespan">10 000</span><span class="imagep"><h3>audi</h3><text>some details of car</text></span></div></div>
</div>

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    您可以将height 设置为#introgreen .imagepheight transition hover effect,如下所示,因此使用jQuery 文本fades-in 并使用CSS 悬停slideupdown 发生,希望对您有所帮助。

    $(document).ready(function(){
    			$("#introgreen .col-md-4").hover(function(){
    			    $(this).find('.imagep text').fadeIn(800);			    
    			    }, function(){
    			    $(this).find('.imagep text').fadeOut(800);			    
    			});
    			
    		});
    #introgreen img{
    	width: 100%;
    	position: relative;
    }
    #introgreen .col-md-4 .wholeimage{
    	position: relative;
    	width: 100%;
    }
    #introgreen .imagespan{
    	position: absolute;
    	left: 0;
    	top: 20;
    	background-color: #d24f0b;
    	padding: 5px 15px;
    	font-size: 18px;
    	font-weight: bold;
    	color: white;
    	z-index: 3;
    }
    #introgreen .imagep{
    	display: inline-block;
    	border: solid 1px white;
    	position: absolute;
    	width: 100%;
    	left: 0;
    	bottom: 0;
    	color: white;
    	background-color: rgba(0,0,0,0.5);
    	height:50px;
    	padding: 20px;
      transition:height 1s ease;
    }
    #introgreen .imagep:hover{
      height:100px;
    }
    .imagep text{
        display: none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="introgreen">
    <div class="col-md-4"><div class="wholeimage"><img src="http://autopazar.co.uk/media/5215/Used_Audi_Q7_2007_Black_4x4_Diesel_Automatic_for_Sale_in_Kent_UK.jpg"><span class="imagespan">10 000</span><span class="imagep"><h3>audi</h3><text>some details of car</text></span></div></div>
    </div>

    【讨论】:

    • @Vasilis Greek 可以通过将鼠标悬停在父元素上来实现相同的效果。
    猜你喜欢
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2010-11-19
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    相关资源
    最近更新 更多