【问题标题】:Need help to hover opacity需要帮助悬停不透明度
【发布时间】:2014-08-17 21:19:11
【问题描述】:

我有两个 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>

【问题讨论】:

  • 能否请您也发布您的 HTML。
  • 很多代码行.. 为什么?

标签: jquery html hover opacity


【解决方案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);
});

【讨论】:

  • 什么都没有发生...这些ID是div“母亲”,其中还有其他相当内容..有问题吗?
  • 如果您想为您的问题提供特定的解决方案,请在您的问题中包含您的 HTML。
【解决方案2】:

试试这个:

$('#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

【讨论】:

  • 他试图淡化“兄弟”,而不是悬停的那个。
  • 真丢脸。谢谢你的评论@Michael_B ;)
猜你喜欢
  • 1970-01-01
  • 2018-10-09
  • 1970-01-01
  • 2018-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-08
  • 2017-06-10
相关资源
最近更新 更多