需要帮助来悬停不透明度

时间:2014-06-26 21:15:53

标签: jquery html hover opacity

我有两个div,一个在另一个旁边,每个都有不同的内容。我想当鼠标站在一个上,另一个是透明的......反之亦然。我正在尝试下面的代码,但它不起作用。我是否还需要在css div中设置不透明度?

$('#id-escolha-right').mouseover(function(){
    $('#id-escolha-left').fadeTo( "slow", 0.3 );
});
$('#id-escolha-left').mouseover(function(){
    $('#id-escolha-right').fadeTo( "slow", 0.3 );
});

继承人html

    <div class="escolha-left" id="id-escolha-left">
    <a href="#" title="Porto Sol Beach" style="text-decoration:none;">
    <div class="box-beach-left">
            <h2>Porto Sol</h2>
            <h1>Beach</h1>
            <p>
                Um hotel à beira do mar, ideal para quem busca relaxar e aproveitar as belezas da ilha.<br>
            </p>
            <div class="prev-beach"></div>
        <img src="imgs/left-pessoas-escolha.png">
    </div>
    </a>
</div>  

<div class="escolha-right" id="id-escolha-right">
    <a href="#" title="Porto Sol Quality" style="text-decoration:none;">
    <div class="box-beach-right">
            <h2>Porto Sol</h2>
            <h1>Quality</h1>
            <p>
                Um business hotel do tamanho certo para eventos sociais e corporativos.<br>
            </p>
            <div class="next-quality"></div>
            </div>
        <img src="imgs/right-pessoas-escolha.png">
    </div>
    </a>
</div>

2 个答案:

答案 0 :(得分:1)

您需要重置您要显示的不透明度。

$('#id-escolha-right').hover(function () {
    $(this).fadeTo("slow", 1);
    $('#id-escolha-left').fadeTo("slow", 0.3);
});
$('#id-escolha-left').mouseover(function () {
    $(this).fadeTo("slow", 1);
    $('#id-escolha-right').fadeTo("slow", 0.3);
});

答案 1 :(得分:0)

试试这个:

$('#id-escolha-right').hover(function() { 
    $(this).next().stop().animate({"opacity": 0}); 
},function() { 
    $(this).next().stop().animate({"opacity": 1}); 
});

$('#id-escolha-left').hover(function() { 
    $(this).prev().stop().animate({"opacity": 0}); 
},function() { 
    $(this).prev().stop().animate({"opacity": 1}); 
});

fiddle

相关问题