In JS, the sidebar changes from the original fixed to relative when the mouse scrolls over the top, and the dynamic style cannot be displayed.

in JS, the sidebar changes from fixed to relative when the mouse is scrolled over the top, and the dynamic style cannot be displayed.

Learning

related codes

/ / Please paste the code text below (do not replace the code with pictures)

< html >
< head >

<style>
    .test {
        top: 100px;
        margin: 10px;
        padding: 10px;
        width: 300px;
        position: relative;
        border: 5px solid black;
        height: 2000px;
        background: -sharpff7a59;

    }
    .rr{height: 100px;margin-top: 200px;background: -sharp1a92cf;position: fixed;
        top: 40px;  }
</style>

< / head >
< body >

< div class= "test" >

Click the button to get offsetTop for the test div.

<button onclick="myFunction()">Try it</button>

offsetTop is: <span id="demo"></span>

<div class="rr"></div>

< / div >

< script >

    var testDiv = document.getElementsByClassName("test")[0];
    var orr=document.getElementsByClassName("rr")[0].innerHTML = testDiv.offsetTop;
    var arr=document.getElementsByClassName("rr");
    var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
window.onscroll=function () {
    var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
    if(orr>=scrollTop){
           //alert(orr)
        arr.style.position="relative";
        arr.style.height=200+"px";

    }
    else {
      // alert()
        arr.style.position="fixed";
        arr.style.height=1000+"px";
    }
}

< / script >

< / body >
< / html >

I want to change the scrolling style through the mouse wheel in js, but the style in console is undefined. I hope God can guide me. Thank you!

Apr.02,2022

var arr = document.getElementsByClassName('rr')

is there less [0]

written here?
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ac4a-2c253.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ac4a-2c253.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?