javascript - Table column slider alternation -
i want create table 4 columns, show 3 columns. ideally have div spans 3 columns , apply overflow: hidden. on click of button, want column 3 (company 2) slide left, , replaced column 4 (company 3), company 3 gets compared against company 1. if button clicked again, company 3 should slide left again, company 2 should slide right , return original position originally. reason doing because in mobile view can't fit in columns.
fiddle can found here: https://jsfiddle.net/smks/u7jhm/197/
html
<div class="div-table"> <div class="div-table-row header-row"> <div class="div-table-col header-row"> </div> <div class="div-table-col header-row">company 1</div> <div class="div-table-col header-row">company 2</div> <div class="div-table-col header-row">company 3</div> </div> <div class="div-table-row"> <div class="div-table-col">comparison 1</div> <div class="div-table-col">yyy</div> <div class="div-table-col">yyy</div> <div class="div-table-col">yyy</div> </div> <div class="div-table-row"> <div class="div-table-col">comparison 2</div> <div class="div-table-col">yyy</div> <div class="div-table-col">www</div> <div class="div-table-col">yyy</div> </div> <div class="divrow"> <div class="div-table-col">comparison 3</div> <div class="div-table-col">uuu</div> <div class="div-table-col">mkkk</div> <div class="div-table-col">yyy</div> </div> </div> <br> <button>compare next</button>
css
.div-table{ display:table; width:auto; border:1px solid #666666; border-spacing:5px;/*cellspacing:poor ie support this*/ padding: 0; text-align: center; } .div-table-row{ display:table-row; width:auto; clear:both; padding: 5px; } .div-table-col{ float:left;/*fix buggy browsers*/ display:table-column; width:200px; border:1px solid #666666; padding: 5px; } .header-row { height: 50px; }
here quick , dirty way - first applied classes third , forth cols, , animated 4th 1 hidden duration of 1 happens instantly. toggle columns 3 , 4 each time button pressed.
$(document).ready(function () { $(".c4").animate({ width: 'toggle', opacity: 'toggle' }, 1); $("button").click(function (event) { event.preventdefault(); $(".c3, .c4").animate({ width: 'toggle', opacity: 'toggle' }); }); });
updated fiddle: https://jsfiddle.net/u7jhm/202/
Comments
Post a Comment