- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现了很多类似的问题,但找不到可以解决我问题的答案。
我有一个 ID 为“first”的 div。我想要的只是当鼠标位于第一个 div 上时向下滑动另一个 ID 为 'second' 的 div,当鼠标不在该 div 上时 slideup div 'second'。
下面的代码运行良好,但存在一些问题。
1) 当鼠标在 - 它滑动两次。
2) 当第二个 div 关闭并且我将鼠标移到 div 上时,它再次滑动
你能帮我得到我想要的结果吗。
html
<div>
<div id="zero"><div>
<div id="my_hover">
<div id="second"></div>
<div id="first"></div>
</div>
<div id="third"></div>
</div>
js
$(document).ready(function(){
$("#first").mouseenter(function(){
$("#second").stop().slideDown("slow");
});
$("#first").mouseout(function(){
$("#second").slideUp("slow");
});
});
最佳答案
最简单的方法是将 pointer-events: none;
添加到 #second
div CSS 并将其定位在 #first
div 之上.
pointer-events: none;
In addition to indicating that the element is not the target of mouse events, the valuenone
instructs the mouse event to go "through" the element and target whatever is "underneath" that element instead.
(...)
The element is never the target of mouse events; however, mouse events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, mouse events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/bubble phases.
$(document).ready(function(){
var slide = $("#second");
$("#first").hover(function(){
slide.stop().slideDown("slow");
},function(){
slide.slideUp("slow");
});
});
#first {
width: 100px;
height: 100px;
background:red;
}
#second {
position: absolute;
display: none;
width: 100px;
height: 100px;
background:blue;
pointer-events: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="second">Second</div>
<div id="first">First</div>
另一种方法是将这两个元素插入到另一个元素中,并为该元素使用 hover
而不是 div #first
。这样,整个区域都是敏感的:
$(document).ready(function(){
var slide = $("#second");
$(".my-hover").hover(function(){
slide.stop().slideDown("slow");
},function(){
slide.slideUp("slow");
});
//for demo:
$('.btn').click(function(){
alert('it works!');
});
});
#first {
width: 100px;
height: 100px;
background:red;
}
#second {
position: absolute;
display: none;
width: 100px;
height: 100px;
background:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=my-hover>
<div id="second"><button class=btn>BUTTON</button></div>
<div id="first">First</div>
</div>
关于javascript - Jquery slideup slidedown 意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28967990/
我希望用户能够单击该 div,向下滑动另一个子 div。当用户单击该子 div 内的按钮时,子 div 将向上滑动。 使用下面的 JQuery,div 可以很好地向下滑动。但是,当我单击按钮时,它会向
我有这行 JavaScript,我看到的行为是 selectedLi 立即消失而没有“向上滑动”。这不是我预期的行为。 我应该怎么做才能让 selectedLi 在被移除之前向上滑动? selecte
$(".item").hover( function () { $(this).slideDown().append( $("Yes/No") );
这个问题已经有答案了: Callback of .animate() gets called twice jquery (2 个回答) 已关闭 9 年前。 我正在使用 jQuery 创建一个多选项卡
我正在使用包含 ul 和 li 标签的 side-nav。 看起来像: Mobile PLATFORM SPECIFIC GUIDES Magento Extensi
是否可以使用.slideUp,但对象只能向上滑动(例如)20px,而不是消失在屏幕之外? HTML: Hide Tab 1 Tab 2 JQUERY: $(".
我正在使用 jQuery/Ajax 脚本来提交表单而无需重新加载页面。我的页面上有多个表单,它们都具有相同的类(并且没有 ID)。使用以下方式提交表单效果很好: $('document').r
我在从事这个项目时似乎正在自学 jquery。 我以为会有一种非常简单的方法来实现这种技术,但我到处搜索都没有成功。这是我们正在查看的页面: http://igs.link-networkonline
单击 div 对象时,slideUp 不起作用。 Jquery 代码: $('#show-about-btn').click(function() { $('#show-about-btn')
当 div 悬停在右侧时,我有一个列表会在右侧弹出。我想使用 jqueries SlideUp/Down 来显示和隐藏列表,这在大多数情况下都有效。但有时该功能会重复触发。不断地打开和关闭。我不知道为
$(document).ready(function() { $('#arrow').click(function () { if ($('#slide1').is(":hid
我将创建一个每周日历。当我切换星期时,我想将旧的星期向左或向右滑动以获取新内容。有谁能够帮助我?目前我没有好主意来实现这个。 非常感谢。 最佳答案 例如向左滑动而不是 .slideUp()您可以使用.
我想做的就是: 有7个数字和7个div,它们相互关联(nr 0与div 0有关系) 当点击其中一个数字时,它应该折叠所有其他未被选中的 div 可以一次多选 综上所述,基本上,页面有一些带有数字的标签
在表格行中显示或隐藏一些 div 后,如何为高度调整设置动画?基本上,在用户在单选组中进行选择并将鼠标悬停在该行之外后,其他单选选项将被隐藏以压缩表单。如果他们将鼠标移回该行,所有单选选项将再次出现。
当我滚动页面时,我想为页眉设置动画。它应该slideUp,添加一个类和slideDown。 slideUp 和 slideDown 按预期工作,但未添加类 header-small。怎么会? $(fu
我有一个我创建的 Accordion 样本;问题很简单:第一次单击任何 Accordion 项目时,slideUp() 动画不起作用。我在链接 jquery 方法方面仍然不太熟练,所以我的问题是:我应
如何确保多个 div 向上滑动?现在我有这个功能: $("div#personal").click(function() { $("div.1").slideUp("slow", function
我创建了一个带有旋转木马导航的 Flexslider。导航被设计为移动屏幕尺寸的垂直列表。 在移动设备上:我想隐藏列表(点击的幻灯片标题除外),以便用户可以看到所选的幻灯片。 在大屏幕上:我只想让简单
我在使用 jQuery slideUp() 方法时遇到问题。我有一个计时器设置为在 1 秒内向上滑动一个 div,然后显示一个段落。我的 div 中有一个位于屏幕中央的 h1 元素。问题是当这个 h1
我有一个图标可以同时触发向上滑动和向下滑动的效果,但是在向下滑动之后,如果我再次按下同一个图标,它就不再起作用了。 $(document).ready(function(){ $('.subc
我是一名优秀的程序员,十分优秀!