jQuery & CSS - Remove/Add display:none

前端 未结 13 2423
遥遥无期
遥遥无期 2020-12-12 12:37

I have a div with this class :

.news{
  width:710px; 
  float:left;
  border-bottom:1px #000000 solid;
  font-weight:bold;
  display:none;
}
<
13条回答
  •  佛祖请我去吃肉
    2020-12-12 13:07

    Considering lolesque's comment to best answer you can add either an attribute or a class to show/hide elements with display properties that differs from what it normally has, if your site needs backwards compatibility I would suggest making a class and adding/removing it to show/display the element

    .news-show {
    display:inline-block;
    }
    
    .news-hide {
    display:none;
    }
    

    Replace inline-block with your preferred display method of your choice and use jquerys addclass https://api.jquery.com/addclass/ and removeclass https://api.jquery.com/removeclass/ instead of show/hide, if backwards compatibility is no problem you can use attributes like this.

    .news[data-news-visible=show] {
    display:inline-block;
    }
    
    .news[data-news-visible=hide] {
    display:none;
    }
    

    And use jquerys attr() http://api.jquery.com/attr/ to show and hide the element.

    Whichever method you prefer it makes you able to easily implement css3 animations when showing/hiding elements this way

提交回复
热议问题