Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer Jumpy Scrolling

I have this code to keep a heading element at the top of another element that scrolls.

It works perfectly in Firefox and Google Chrome however in IE it's excruciatingly jumpy. The code itself is very simple and I can't think how to potentially improve it.

In Chrome and Firefox the heading sits at the top permanently still all the time, however in IE it jumps around like a small child that got hold of the bag of sugar.

I can't change the HTML layout because of the JQueryUI sortable functionality I'm using

Anyway, here's the code:

http://jsfiddle.net/0va4dn0q/8/

$('.container').scroll( function() {
    var fromTop = $(this).scrollTop(),
        Header = $(this).find('.header');
    Header.css('margin-top', fromTop + 'px');
});

$('.sortable').sortable({
    connectWith: '.sortable',
    placeholder: 'ui-state-highlight'
});
div {
   width:300px; 
}
.sortable {
    float:left;
    margin:3px solid red;
    min-height:200px;
}
.container {
    height:200px;
    overflow-x:hidden;
    overflow-y:auto;
    position:relative;
    cursor:move;
}
.header {
    position:absolute;
    top:0;
    background-color:orange;
    height:20px;
    text-align:center;
    line-height:20px;
}
.main {
    padding-top:20px;
    color:white;
    background-color:black;
    height:1000px;
}
.ui-state-highlight {
    height:200px;   
}
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div class="sortable">
    <div class="container">
        <div class="header">Header 1</div>
        <div class="main">hello<br/>hello<br/>hello<br/></div>
    </div>
    <div class="container">
        <div class="header">Header 2</div>
        <div class="main">bye<br/>bye<br/>bye<br/></div>
    </div>
</div>
<div class="sortable">
    <div class="container">
        <div class="header">Header 3</div>
        <div class="main">splurge<br/>splurge<br/>splurge<br/></div>
    </div>
    <div class="container">
        <div class="header">Header 4</div>
        <div class="main">lorem ipsum<br/>dolor<br/>sit<br/></div>
    </div>
</div>
like image 311
Jamie Barker Avatar asked Mar 16 '23 20:03

Jamie Barker


1 Answers

The header should be outside of the container, while the container should have a margin-top of 20px, see fiddle

 <div id="header">Header</div>
 <div id="container">
    <div id="main"></div>
 </div>
like image 150
hamecoded Avatar answered Mar 23 '23 12:03

hamecoded