javascript - 如果 div 是 Fl​​ex 的,我可以使其弹跳吗?

标签 javascript jquery html css flexbox

我试图让 div 内的图像在鼠标悬停在其上方时反弹。

为了解释我遇到的问题,我在下面的代码片段中快速模拟了我想要发生的情况。

我希望每当我的鼠标移到图像/文本/任何内容上时,文本都会稍微弹起。

我唯一能想到的是,只要元素属于 flex 盒方案的一部分,它们就不会反弹,但是,我无法找到任何文档来证明这一点。

有人可以解释一下如何在使用 Flexbox 时让这种情况发生吗?

$(document).ready(function() {
  $('.text').hover(function() {
   $(this).toggle("bounce",{times: 3}, "slow");
    });
});
.one{
  margin:0;
  }

.container{
  height:500px;
  width:500px;
  background-color:gray;
  display:flex;
  flex-wrap:wrap;
  align-items:horizontally;
  justify-content:space-around;
  align-items:center;
   }
.dog{
  background-color:red;
  height:100px;
  width:100px;
  }
.cat{
  background-color:blue;
  height:100px;
  width:100px;
  }
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
  <head>
    </head>
  <body>
    <div class="one">
      <div class="container">
        <div class="dog">
          <div class="text">Hello Dog</div>
        </div>
        <div class="cat">
          Hello Cat
        </div>
      </div>
    </body>

最佳答案

我添加了 jquery-ui 脚本/css,它工作正常:

您使用的反弹效果是 jQuery UI library 的一部分- 参见this for reference .

请参阅下面的演示:

$(document).ready(function() {
  $('.text').hover(function() {
    $(this).toggle("bounce", {
      times: 3
    }, "slow");
  });
});
.one {
  margin: 0;
}
.container {
  height: 500px;
  width: 500px;
  background-color: gray;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
}
.dog {
  background-color: red;
  height: 100px;
  width: 100px;
}
.cat {
  background-color: blue;
  height: 100px;
  width: 100px;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <div class="one">
    <div class="container">
      <div class="dog">
        <div class="text">Hello Dog</div>
      </div>
      <div class="cat">
        Hello Cat
      </div>
    </div>
</body>

关于javascript - 如果 div 是 Fl​​ex 的,我可以使其弹跳吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41269551/

相关文章:

javascript - 使用javascript获取输入字段中的光标位置

javascript - 如何获取与数组具有相同名称标签的所有输入字段(jQuery)

javascript - 在 Highcharts 的图表中只添加一个可点击的点?

javascript - 如何防止浏览器调用基本身份验证弹出窗口并使用 Jquery 处理 401 错误?

javascript - 您可以使用书签将网页嵌入到网站吗?

javascript - 如何禁用youtube提供的右键单击选项

javascript - VeeValidate 'required_if:' 规则

javascript - 纯函数: state content vs.状态引用

php - 无法显示多张图像

javascript - 提交表单时数据表中的复选框不起作用