javascript - 在悬停Jquery上添加图片背景和文字
问题描述
我正在尝试更改以在悬停时更改图片。这是我到目前为止所做的:
HTML
<div class="picture">
<div class="text">
<h1>Hey everyone!</h1>
</div>
</div>
CSS
.picture{
width: 200px;
height: 200px;
background-image: url("https://www.w3schools.com/css/trolltunga.jpg");}.text{
background-color: rgba(255,0,0,0.8);
width:200px;
height: 200px;
display: none;}
javascript
$(".picture").hover(function(){
$(this).children(".text").fadeToggle();});
解决方案
正如您在此示例中看到的那样,它工作正常:
$(".picture").hover(function() {
$(this).children(".text").fadeToggle();
});
.picture {
width: 200px;
height: 200px;
background-image: url("https://www.w3schools.com/css/trolltunga.jpg");
}
.text {
background-color: rgba(255, 0, 0, 0.8);
width: 200px;
height: 200px;
display: none;
}
<div class="picture">
<div class="text">
<h1>Hey everyone!</h1>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
推荐阅读
- javascript - 属性或方法“sendResetMail”未在实例上定义,但在渲染期间引用
- python - 如何在 tkinter 中选择小部件的所有实例?
- macos - 使用“读取”模式的 Logstash 6.4.1(及更高版本)“logstash-input-file”在 macOS 上无法按预期/期望工作
- html - 如何为反应组件提供 Id 或 Attribute
- embedded - 为什么数据表中 INT0 的向量数是 1 而不是 2?
- excel - Excel - 冻结计算的日期,直到日期本身已经过去
- haskell - Haskell 在另一个函数中使用多个函数
- int - 什么时候不适合使用 inttypes.h?
- php - PHP 文件数组有数据但大小和错误为 0
- laravel - 如何使用 slug 或 id 创建路由