FadeIn one element and fadeOut all

时间:2015-05-08 14:37:20

标签: javascript jquery

我试图用jQuery淡化一个元素,然后点击另一个元素fadeOut那个元素。我知道如何淡化div,但我如何淡化所有其他人? 谢谢你的帮助!

div有{ids #id1 #id2 #id3 #id4

这是我的Jquery

function trying(id){

var fade_in =function (e){
        $(id).fadeIn();
    };
    $(id).click(fade_in);
};

trying("#id1");
trying("#id2");
trying("#id3");
trying("#id4");

4 个答案:

答案 0 :(得分:1)

正如安迪所说,你应该给这些元素一个班级。让我们称之为马铃薯,因为谁不爱土豆。

CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase

答案 1 :(得分:0)

这个怎么样(假设这些元素是div):

$('div[id*=id]').click(function(){//when any div whose id contains 'id'

     $('div[id*=id]').not($(this)).hide();
     //hide all divs whose id contains 'id' except the current `div` clicked
});

答案 2 :(得分:0)

我并没有完全卖掉使用javascript来提供你想要做的事情的视觉效果;但是,我会使用javascript-在这种情况下jquery-将类状态应用于元素。如果此示例有帮助,请告诉我http://output.jsbin.com/kuxefunibi/

我正在做的就是将一个.active类应用于包装器,然后将.current类应用于当前单击的块。有了这个,只要.active存在,除非.blocks类应用了.current类,否则它内部的所有.block都是半透明的。然后,只有那时特定的.block.current才会稳固。

$(function() {
  $('.block').on('click', function() {
    $(this)
      .siblings().removeClass('current').end()
      .addClass('current')
      .parent().addClass('active');
    return false;
  });
});
* {
  box-sizing: border-box;
}
.block-list.active .block {
  transition: opacity 0.2s;
  opacity: 0.25;
}
.block-list.active .current {
  opacity: 1;
}
.block {
  width: 25%;
  padding: 30px 15px;
  float: left;
  background-color: #333333;
  cursor: pointer;
  color: #ffffff;
  text-align: center;
}
<!DOCTYPE html>
<html>

<head>
  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <meta charset="utf-8">
  <title>Testing</title>
</head>

<body>
  <div class="block-list">
    <div class="block block-1">some text here</div>
    <div class="block block-2">some text here</div>
    <div class="block block-3">some text here</div>
    <div class="block block-4">some text here</div>
    <div class="block block-5">some text here</div>
    <div class="block block-6">some text here</div>
    <div class="block block-7">some text here</div>
    <div class="block block-8">some text here</div>
  </div>
</body>

</html>

答案 3 :(得分:0)

这是你的意思吗? jsfiddle fadein fadeoutall我也添加了一些评论。

这是js代码:

   var result = "Test æ".Unidecode();
   Console.WriteLine(result) // Prints Test ae
相关问题