jquery - 使用滑动 jQuery 在悬停时显示/隐藏元素

标签 jquery css jquery-hover

我遇到了一些困难,似乎找不到答案。

所以,我有一个名为 .accom-img 的图像类和一个名为 .accom-desc 的带有描述的 div 类。当我将鼠标悬停在 .accom-img 上时,我使用 slideUp() 隐藏它并显示 .accom-desc(隐藏在页面加载上但位于它们的正下方)仅使用 .show()

当鼠标离开 .accom-desc 时,我希望图像向下滑动。除了鼠标离开 .accom-desc 时,我可以让一切正常工作。图像只是保持隐藏状态。

请帮我解决我做错的地方。谢谢!

       jQuery(document).ready(function() {
    	jQuery('.accom-desc').hide();

    	jQuery('.accom-img').hover(function() {
    		jQuery('.accom-img').slideUp();
    	}, function() {
          	jQuery('.accom-desc').show();
    	});

    	jQuery('.accom-desc').mouseleave(function() {
    		jQuery('.accom-img').slideDown();
    	}, function() {
            jQuery('.accom-desc').hide();
    	});
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<div class="accom-container">
  <div class="accom-desc"> 
    <h4>6 Sleeper House</h6> 
    <ul class="accom-ul"> 
      <li>2 x en-suite bedrooms each with a double bed with mosquito net.</li> 
      <li>2 x single beds with mosquito nets in the living area.</li> 
      <li>Fridge and chest freezer and fully fitted kitchen.</li> 
      <li>Television with DVD-player..bring lots of DVD's and own DSTV- decoder.(DSTV dish and connection available)</li> <li>Own private Jacuzzi</li> 
    </ul> 
  </div> 
</div>

最佳答案

可能是因为你的函数是同时运行的。你需要做这样的事情:

jQuery('.accom-desc').mouseleave(function() {
        jQuery('.accom-img').slideDown(1000, function() {
        jQuery('.accom-desc').hide();
    }));

关于jquery - 使用滑动 jQuery 在悬停时显示/隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914812/

相关文章:

css - 如何更改 col-xs Bootstrap 的宽度?

php - Prestashop 1.7 - 顶部菜单中的下拉子类别

html - 我试着让三张图片并排 float ,宽度为 33%。为什么右边有多余的空间?

jquery - 如何隐藏/显示依赖于 2 个不同元素的元素

java - 一对一聊天 Atmosphere 框架

javascript - 图像未在 IE 8 中显示

jQuery slideToggle() 在 Chrome/Safari 中的特殊行为

jQuery 动画宽度而不回流内容?

javascript - 鼠标绑定(bind)图片后悬停效果

javascript - jquery 悬停气泡导致循环闪烁效果