Jquery背景幻灯片

oiopk7p5  于 2023-11-17  发布在  jQuery
关注(0)|答案(1)|浏览(121)

我想知道是否有可能改变使div跟随它的表格单元格的大小?目前我只能显示另一个div上面的东西。这是我到目前为止。
https://jsfiddle.net/amosangyongjian/mmqasf5t/54/

$(document).ready(function(){
    $("td").hover(function(){
    $(this).find(".expand").slideDown("slow");
  },function(){
    $(this).find(".expand").slideUp("slow");
  });
});

字符串

f4t66c6m

f4t66c6m1#

td {
  width:100px;
  height:100px;
  position:relative; /* ADD THIS */
}
.expand {
  display: none;
  position: absolute;
  top: 0; left:0; width: 100%; height: 100%; /* ADD */
  z-index: 1;
  background: red;
  /*height: auto; width: 100%;  REMOVE */
  overflow: hidden;
}
    
.static {
  position: absolute;
  z-index: 0;
  background: yellow;
  text-align: center;
}

字符串
这里有一个更干净的解决方案,在HTML,CSS,jQuery中有一些小的变化

jQuery(function( $ ) {

  $("td").hover(function() {
    $(this).find(".expand").stop().slideToggle("slow");
  });

});

x

td {
  width:100px;
  height:100px;
  position:relative;
}
.expand {
  display:none;
  position:absolute;
  top:0; left:0; width:100%; height:100%;
  background:red;
  overflow:hidden;
}
.static {
  position:absolute;
  background:yellow;
  text-align:center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1" id="tableclass">
  <tr>
    <td>
      <div class="static">Hello1</div>
      <div class="expand">Expanded</div>
    </td>
    <td>
      <div class="static">Hello2</div>
      <div class="expand">Expanded</div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="static">Hello3</div>
      <div class="expand">Expanded</div>
    </td>
    <td>
      <div class="static">Hello4</div>
      <div class="expand">Expanded</div>
    </td>
  </tr>
</table>

的字符串
这是另一个使用根本没有JavaScript的例子
但CSS3 transitionheight:0;height:100%;

td {
  width:100px;
  height:100px;
  position:relative;
}
.static {
  position:absolute;
  background:yellow;
  text-align:center;
}
.expand {
  position:absolute;
  overflow:hidden;
  top:0; left:0; width:100%; height:0;
  background:red;
  transition: 0.5s;
}
td:hover .expand{
  height:100%;
}
<table border="1" id="tableclass">
  <tr>
    <td>
      <div class="static">Hello1</div>
      <div class="expand">Expanded</div>
    </td>
    <td>
      <div class="static">Hello2</div>
      <div class="expand">Expanded</div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="static">Hello3</div>
      <div class="expand">Expanded</div>
    </td>
    <td>
      <div class="static">Hello4</div>
      <div class="expand">Expanded</div>
    </td>
  </tr>
</table>

相关问题