javascript - js div is set to overflow: scroll; the li tag specifies scrolling to a certain position
伊谢尔伦
伊谢尔伦 2017-05-19 10:34:26
0
1
805

window.scrollTo(0, 300); This is for scrolling the window, but scrolling the li label below,
For example, scrolling li[9] to the top, what should be done?

        <p id="example-2"> 
            <p>这是标题</p>
            <p id="p1" style="height: 5rem;border: 1px solid #007AFF;overflow: scroll;">
                <ul>
                    <li>1</li>
                    <li>2</li>
                    <li>3</li>
                    <li>4</li>
                    <li>5</li>
                    <li>6</li>
                    <li>7</li>
                    <li>8</li>
                    <li>9</li>
                    <li>10</li>
                    <li>11</li>
                    <li>12</li>
                </ul>
            </p>
        </p>
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
仅有的幸福
p.addEventListener('scroll', function (){
    //...
})

Set the scrollTop of p to the offsetTop of li


Code address

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template