/ Published in: JavaScript
Depends on the number of tr tag, it will add a negative margin-top except less than 15
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { var len = $('#infoinner tr').size(); if (len>15 && len<50){ var roundlen = Math.round(len*1.5); } else if (len>50 && len<75){ var roundlen = Math.round(len*2.4); } else if (len>75 && len<100){ var roundlen = Math.round(len*3.6); } else if (len>100 && len<150) { var roundlen = Math.round(len*4.8); }else if (len>150 && len<200) { var roundlen = Math.round(len*6); }else { var roundlen = Math.round(len*7); } if(len<15) { var margintop = '0'; $('#infoinner table').css('margin-top',margintop); }else{ var margintop = '-'+ roundlen +'px'; } $('#infoinner').css('margin-top',margintop); });