


How to implement jQuery to scroll the scroll bar in a div to a specified position
Dec 24, 2016 pm 03:03 PMThe example in this article describes how jQuery implements scrolling the scroll bar in a div to a specified position. Share it with everyone for your reference, as follows:
1. Js code:
onload = function () { //初始化 scrollToLocation(); }; function scrollToLocation() { var mainContainer = $('#thisMainPanel'), scrollToContainer = mainContainer.find('.son-panel:last');//滾動(dòng)到<div id="thisMainPanel">中類名為son-panel的最后一個(gè)div處 //scrollToContainer = mainContainer.find('.son-panel:eq(5)');//滾動(dòng)到<div id="thisMainPanel">中類名為son-panel的第六個(gè)處 //非動(dòng)畫效果 //mainContainer.scrollTop( // scrollToContainer.offset().top - mainContainer.offset().top + mainContainer.scrollTop() //); //動(dòng)畫效果 mainContainer.animate({ scrollTop: scrollToContainer.offset().top - mainContainer.offset().top + mainContainer.scrollTop() }, 2000);//2秒滑動(dòng)到指定位置 }
2. Html code:
<div id="thisMainPanel" style="height:200px;overflow-y: scroll;border:1px solid #f3f3f3;"> <div class="son-panel">我是類容區(qū)域-1</div> <div class="son-panel">我是類容區(qū)域-2</div> <div class="son-panel">我是類容區(qū)域-3</div> <div class="son-panel">我是類容區(qū)域-4</div> <div class="son-panel" style="height:160px;">我是類容區(qū)域-5</div> <div class="son-panel">我是類容區(qū)域-6</div> <div class="son-panel">我是類容區(qū)域-7</div> <div class="son-panel">我是類容區(qū)域-8</div> </div>
I hope this article will help everyone in jQuery programming.
For more jQuery methods to implement scrolling the scroll bar in a div to a specified position, please pay attention to the PHP Chinese website for related articles!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)