我有這樣的代碼來保持標題元素在滾動的另一個元素的頂部。Internet Explorer Jumpy滾動
它在Firefox和谷歌瀏覽器中完美工作,但在IE瀏覽器中令人難以忍受。代碼本身非常簡單,我無法想象如何改進它。
在Chrome和Firefox中,標題始終始終位於頂部,但是在IE中它像一個拿着糖袋的小孩子一樣跳轉。
我不能因爲JQueryUI
sortable
功能我用
無論如何改變HTML佈局,下面的代碼:
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>
+1根據我提供的所有信息給出了很好的答案。令人討厭的是,還有一個怪癖(/我哭了一下)。標題並不總是用作句柄,因爲它們可以是UI元素(jQueryUI Slider)而不是文本元素。不幸的是,如果你把處理程序關閉,然後嘗試拖動滾動條,你可以得到這個:http://jsfiddle.net/yod3s5vm/5/ –
這個答案只是給了我一個想法,雖然... –
好。如果這個想法有效,那麼將其作爲未來讀者的答案發布。如果您遇到困難,請告訴我,我會進一步瞭解。 –