所以我有这个功能,它很长很复杂。
现在,如果窗口宽度发生变化,我可以让它工作,但滚动事件需要先触发。
如何让它在调整窗口大小时起作用?
$(document).bind("scroll.myScroll", function () {
var scrollTop = $(document).scrollTop();
masthead = $(".mast-head").outerHeight();
notef = $(".note-f").outerHeight();
frontcontainheight = $(".center").outerHeight();
//derivative variable
abpos = (frontcontainheight / 2.1);
sidebarwidth = $(".sidebarholder").width();
dataheight = $(".data-top").outerHeight(true);
controlwidth = $(".loop-contain").outerWidth();
innerwidth = $(".front-contain").outerWidth();
//get side-contain width dynamically
//derivative variable
sidecon = (controlwidth - innerwidth);
elem = $(".center");
paddingTopBottom = elem.innerHeight() - elem.height();
console.log (controlwidth);
if ($(window).width() > 1200) {
if (scrollTop > notef + dataheight + masthead - 50 + paddingTopBottom) {
$('.side-contain').css({
position: "fixed",
left: sidebarwidth + innerwidth,
top: "50px",
width: sidecon - "24"
});
}
if (scrollTop < notef + dataheight + masthead - 50 + paddingTopBottom) {
$('.side-contain').css({
position: "relative",
left: "",
top: "",
width: ""
});
}
if (scrollTop > abpos + masthead - 50 + paddingTopBottom) {
$('.side-contain').css({
position: "absolute",
left: innerwidth,
top: abpos - notef, // if the scroll is more than half the height of front-contain then lock to that position, ie. the amount scroll of front-contain - 63px.
width: sidecon - "24"
});
}
} else if ($(window).width() < 1200) {
$('.side-contain').css({
position: "relative",
left: "",
top: "",
width: ""
});
}
});