I have 2 web parts on my AllItems.aspx page (one HTML Form web part & one list view). I want to fix the HTML web part on the top of the page, so that it is also visible on scrolling the page down. The other webpart (list view) should begin below the html webpart and should be scrollable (as normal). Can someone help?
EDIT: Actual Code & Problem
I could fix the html web part and show the list view below with the following code:
$(document).ready(function () {
$("#MSOZoneCell_WebPartWPQ3").css("position", "fixed");
var marginNew = $("#MSOZoneCell_WebPartWPQ3").outerHeight() * 1.5;
$("#MSOZoneCell_WebPartWPQ2").css("margin-top", marginNew + "px");
});
The problem now is, that on scrolling the two web parts overlap!
EDIT 2: New attempt
With the following code I can fix "normal" HTML elements, like divs. But the logic won't work for my webpart-containing SP page!
$('#s4-workspace').on('scroll', function() {
var pos = $('#s4-workspace').scrollTop();
if(pos > webPartPosition) {
document.getElementById("MSOZoneCell_WebPartWPQ3").style.top = pos + "px";
} else {
document.getElementById("MSOZoneCell_WebPartWPQ3").style.top = webPartPosition + "px";
}
});
I guess that I can't make position settings, because the listview web part follows below and prevents the upper one to be able to move.