I created a piece of code for a cross-brower/cross-device solution for locking a div on a custom vBulletin page. The div locks and scrolls along with the page scrolling as soon as it's reached.
To do this, I make use of another div that is on the same height as the div that needs to lock and scroll along. Also, no fixed position is used because mobile behavior would make the div disappear completely. It's not the prettiest solution, but at least it seems the most potential as a cross-browser and device solution.
However, when adding it, it works in all majors browsers and on platforms including iOS and Android, but it does not work in IE. For some mysterious reason, IE does not seem to be able to get the pageYOffset and/or offsetTop values.
Code:
<script type="text/javascript">
window.onscroll = function (e) {
var basediv = document.getElementById('basediv').offsetTop;
var setdiv = document.getElementById('setdiv');
if (window.pageYOffset < basediv) {
setdiv.style.top = "0px";
}
else {
setdiv.style.top = window.pageYOffset - basediv + "px";
}
}
</script>
See the pageYOffset & div.offsetTop being called for onscroll
link has been removed.
Thanks in advance for the help!!