javascript - Jquery background slide down -
i wondering if possible change make div follow size of table cell? @ moment can display above div. have far.
https://jsfiddle.net/amosangyongjian/mmqasf5t/54/
$(document).ready(function(){ $("td").hover(function(){ $(this).find(".expand").slidedown("slow"); },function(){ $(this).find(".expand").slideup("slow"); }); });
td { width:100px; height:100px; position:relative; /* add */ } .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; }
and here's cleaner solution minor changes in html, css, jquery
jquery(function( $ ) { $("td").hover(function() { $(this).find(".expand").stop().slidetoggle("slow"); }); });
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>
and here's example uses no javascript @ all
css3 transition
height: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>
Comments
Post a Comment