FIXED HEADER TABLE ____When Clicking on scrollbar icon in ie11 flickers when using positioning as i cannot change the structure as it is dynamically coming from different sources and gets in table body structure
<tbody><tr></tr><tr></tr></tbody>
here is the fiddle attached works fine in chrome but when i check in ie it flickers horriblly when clicking on div vertical scrollbar below or above icon
Any Css or html solution is also acceptable until if there is no change in html structure
DEMOJs Fiddle Demo JQUERY
$(document).ready(function() { $('#theDiv').on('scroll', function () { $('#headerRow td,#headerRow th').css({'position':'relative','background':'red','top':$('#theDiv').scrollTop()-1}); }); });
4 Answers
Answers 1
First we wrap #theDiv
in a #theDivWrap
(using jQuery) and use the css to style it...
The idea is to duplicate header row into a new div appended to #theDivWrap
via JS
Now loop through table heading elements and create a div based similar styled heading which will come over table and is prepended to #theDivWrap
and stays there forever even on scroll because wrap is not overflow auto...
https://jsfiddle.net/5dqnumh6/39/
Adjust negative margin bottom of .headerRow
to suit your needs ;)
Answers 2
As Ie doesn't support overflow property for table group elements. So we can add a workaround to support the required behaviour. Add this css to your fiddle and try it will work.
tbody{display:block;height:auto;}
This will make your flicker go away in ie older versions. Although its a hack to make it work but there is no other pure css way. For more details and explanation you may want to read this link. Updated fiddle is here. But as you told me flickering not goes away.A workaround exists but it requires changing in ie settings. Go to internet options, navigate to advanced and scroll down until you see browsing section and uncheck "enable smooth scrolling". But I don't know whether it suits your requirement or not
Answers 3
This has been noted to be an IE11 bug, and according to this other SO question from 2014, shows up under the following conditions:
Three things can cause IE 11 flickering/choppy/delay for fixed position element while scrolling:
- If you have an "overflow: auto;" on the parent container element, remove it.
- Remove background-attachment:fixed; from the fixed position element.
Remove border-radius from the fixed position element (mobile IE only).
(Accepted answer by @Adamy)
Well, removing auto-overflow from your code takes away the whole purpose, so it's not the best solution here, and the others don't apply. What seems to work however (according to this MS Connect bug) is some HTML changes, separating the header row, and adding a custom scroll function to the actual table body. This JsFiddle page (kindly provided by folks that responded to the MS bug) has a working example:
https://jsfiddle.net/84y0vtyx/
(Including only part of the example with relevant comment. Full explanation requires reviewing the JsFiddle example.)
/* Only WinIE will fire this function. All other browsers scroll the TBODY element and not the DIV */ /* This is to hide the SELECT elements from scrolling over the fixed Header. WinIE only. */ /* toggleSelectBoxes added on 2005-01-28 */ /* Terence Ordona, portal[AT]imaputz[DOT]com */ window.onload = function() { addIEonScroll(); }
Answers 4
Hi here is my update based on your comment. I copied the HTML part from your js Fiddle and just added this style tag to the above the table div and it works perfectly in microsoft edge and other browsers with no Jquery needed:
<style> #headerRow { position: fixed !important; top:0px; background:Red; } </style>
////OLD
I apologies as you have mentioned that you cannot change the html table structure that comes down however see my old answer below which i wrote without this consideration. Can you consider using css to traverse the fixed table that comes down and apply a fixed position to the top header row? I have read that you can give a fixed position and a background color to a table row so that it remains fixed and the background prevents the text from overlapping How to make table row fixed at the top
You can use css to select the top row of the table: Css:
table tr:first-child { position: fixed; top:0px; background:#FFF; }
/// old answer:
Please may i suggest that you forget about using a document scroll event and just create a header with an absolute position if it is a div with an overflow scroll or a fixed position if it is just to remain fixed as the window scrolls. you can specify widths for your colums so that the fixed header lines up. so something along these lines (im just typing on my phone):
<table style="position:fixed; width:100% "> <tr> <th width="50%"> Test1 </th> <th width="50%"> Test2 </th> </tr> </table> <table style="margin-top:25px; width:100% "> <tr> <td width="50%"> a </td> <td width="50%"> b </td> </tr> <tr> <td width="50%"> c </td> <td width="50%"> d </td> </tr> </table>
Especialy if we are talking cross browser compatibilty here- the simpler and most basic html/ css implementation the better. Css has provided us with a fixed class. There is no need to use jquery to watch your documents scroll.
0 comments:
Post a Comment