jquery - 将鼠标悬停在 div 上会更改另一个 div 标题

标签 jquery css mouseover jquery-hover

我会尽力解释这一点。 我有 5 个盒子,想要 1 个盒子有不同的标题颜色。当我将鼠标悬停在其他 4 个框上时,我希望事件框标题发生变化,从而使新标题的颜色不同。鼠标关闭,标题将保持该颜色。

我将其设置为当您将鼠标悬停在图像上时,段落文本会根据图像发生变化。当发生悬停操作时,我有占位符文本消失。

我尝试的一切都不起作用,但我知道有一个答案。太感谢了!

这是我的代码:

<div class="process">     
            <div class="step box-1">
                <img src="img/seed.jpg" rel="first-step">
                <h3>SEED</h3>
            </div>
            <div class="step box-2">
                <img src="img/seedling.jpg" rel="second-step">
                <h3>CULTIVATE</h3>
            </div>
            <div class="step box-3">
                <img src="img/drop" rel="third-step">
                <h3>DISTILL</h3>
            </div>
<h4 class="steps first-step"> 
            Powerful, effective essential oils come from seeds and plants that are verified for their essential oil potential by Young Living experts, partnering with university experts. 
            </h4>
            <h4 class="steps second-step">
            Young Living farms, located around the globe, are dedicated to perfecting the best growing and harvesting methods. Our experts also travel the world visiting our co-op farms to verify that their growing and cultivating processes match our high standards. These operations provide an ongoing source for essential oils that meet Young Living's demanding quality standards. 
            </h4>
            <h4 class="steps third-step">
            Combining ancient and modern techniques, Young Living is recognized as an innovator in essential oil distillation. We use a gentle, proprietary technique for steam extracting the most effective essential oils, as well as using cold pressing and resin tapping methods for select oils. 
            </h4> 
            <div>

JS:

$(document).ready(function () {
var $placeholder = $('.placeholder');
$('.step> img').hover(function() {
var $rel = $(this).attr('rel');
$placeholder.hide();
});
});

$(document).ready(function () {
var $captions = $('.steps');
$captions.hide();
$('.step> img').hover(function() {
var $rel = $(this).attr('rel');
$captions.hide();
$('.steps.'+ $rel +'').show();
});
});

最佳答案

试试这段代码。

$(document).ready(function () {
    var $placeholder = $('.placeholder');
    var $captions = $('.steps');
    $captions.hide();
    $('.step> img').hover(function() {
        var $rel = $(this).attr('rel');
        $captions.hide();
        $placeholder.hide();
        $('.step h3').css('color', 'black');
        $(this).siblings('h3').css('color', 'red');
        $('.steps.'+ $rel +'').show();
    });
});

首先,将所有 .step h3 设置为颜色 black。然后将事件的 h3 设置为 red

关于jquery - 将鼠标悬停在 div 上会更改另一个 div 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29958275/

相关文章:

html - 在部分容器周围填充

jquery - 浏览器在动画/移动元素上未触发鼠标悬停/鼠标输入

html - 当光标悬停在下拉菜单按钮上时,文本会变成粗体?

javascript - 我需要将 JSON 数据从文件读取到我的网页上

javascript - 一种更优雅的节流 jQuery $().each 的方法?

javascript - 我想要第二次弹出时输入值不被清除

jquery - 试图将鼠标悬停在一个 div 上以激活另一个 div 的淡入淡出

Javascript方法执行和触发事件

css - 如何在 CSS 关键帧上跳转到动画的另一个阶段?

css - 固定的 div 超出包装