jquery - 具有相同类的多个 div,所有这些都只有一个 jquery

标签 jquery html css

我的 jQuery 代码有点问题。我有多个具有相同类的 div 我动态生成此 div。 jQuery 非常简单,只需将 div 顶部移动到一个精确的 px 数字,然后在这个 div 的正下方显示另一个 div。

问题是当我将光标移动到 div 上时,我不知道如何选择悬停的 div 并且不同时移动其他 div。

$(document).ready(function(){
	$("h1").hide();
    $(".pin-holder").mouseenter(function(){
    $(".img-frame").animate({bottom: '80px'});
		$(".hidden-title").slideToggle();
		 $("h1").fadeIn(600);
    });
	 $(".pin-holder").mouseleave(function(){
        $(".img-frame").animate({bottom: '-0px'});
		$(".hidden-title").slideToggle();
		$("h1").fadeOut(600);

       });
    });
.pin-holder{
     position:relative;
     display:inline-block;
     margin-left:95px;
     margin-top:50px;
     width:300px;
     height:300px;
     overflow:hidden;/*+opció*/
}
.img-frame{
     display:inline-block;
     position:absolute;
     width:300px;
     height:300px;
}
.hidden-title{
     position:absolute;
     bottom:0;
     width:100%;
     height:80px;
     background-color:red;
     display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='pin-holder'>
    <div class='img-frame'><a href='#'><img src='pins/pic01.png' height='300' width='300'/></a></div>
        <div class='hidden-title'><h1>PLEASE WORK!</h1></div>
    </div>
    <div class='pin-holder'>
        <div class='img-frame' id='frame01'><a href='#'><img src='pins/pic02.png' height='300' width='300'/></div>
        <div class='hidden-title'><h1>PLEASE WORK!</h1></div>
</div>

最佳答案

这是您想要的行为吗?

$(document).ready(function(){
	$("h1").hide();
    $(".pin-holder").mouseenter(function(){
    debugger;
    $(this).animate({bottom: '80px'});
		$(this).find(".hidden-title").slideToggle();
		 $(this).find("h1").fadeIn(600);
    $(this).find('img').hide()
    });
	 $(".pin-holder").mouseleave(function(){
   debugger;
   $(this).find('img').show()
        $(this).animate({bottom: '-0px'});
		$(this).find(".hidden-title").slideToggle();
		$(this).find("h1").fadeOut(600);

       });
    });
.pin-holder{
     position:relative;
     display:inline-block;
     margin-left:95px;
     margin-top:50px;
     width:300px;
     height:300px;
     overflow:hidden;/*+opció*/
}
.img-frame{
     display:inline-block;
     position:absolute;
     width:300px;
     height:300px;
}
.hidden-title{
     position:absolute;
     bottom:0;
     width:100%;
     height:80px;
     background-color:red;
     display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='pin-holder'>
    <div class='img-frame'><a href='#'><img src='pins/pic01.png' height='300' width='300'/></a></div>
        <div class='hidden-title'><h1>PLEASE WORK!</h1></div>
    </div>
    <div class='pin-holder'>
        <div class='img-frame' id='frame01'><a href='#'><img src='pins/pic02.png' height='300' width='300'/></div>
        <div class='hidden-title'><h1>PLEASE WORK!</h1></div>
</div>

关于jquery - 具有相同类的多个 div,所有这些都只有一个 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44070395/

相关文章:

html - 嵌入式 Flash 媒体播放器未在网页加载时自动启动

html - 边距变小

twitter-bootstrap - 为什么 flex-fill 不在 Bootstrap 中创建相等的宽度?

c# - 如何访问服务器上的Jquery TreeView?

php - 如何显示给定 php 组合框中的项目的不同 php 表?

html - 页脚不粘

javascript - 以编程方式调整 H div 和 C div 的大小以及调整器

javascript - 使用 Ajax 在提交时显示两个图像

javascript - 简单电话 RegXP 返回 : Uncaught SyntaxError: Invalid or unexpected token

javascript - jquery提交没有表单的url查询字符串