Div 滚动条滚动到指定的位置

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<script type="text/javascript" src="resource/jquery-1.9.1.min.js"></script>

</head>

<script type="text/javascript">

$(function(){

//  $("#container").scrollTop($("#test5").scrollHeight ()); 不行

$("#container").scrollTop($("#test4").offset().top)

});

</script>

<body style="text-align:center">

<!--

var div = document.getElementById(‘divDetail‘);

div.scrollTop = div.scrollHeight;  -->

<div id="container" style="width:430px;height:300px;background:#00FF00;overflow:auto">

<div  id="test1" style="width:400px;height:300px;background:#FFFFFF">

</div>

<div  id="test2" style="width:400px;height:300px;background:#000000">

</div>

<div  id="test3" style="width:400px;height:300px;background:#00FF00">

</div>

<div  id="test4" style="width:400px;height:300px;background:#0000FF">

</div>

<div  id="test5" style="width:400px;height:300px;background:#FFFF00">

</div>

</div>

</body>

</html>

IE8 下,亲测可用

时间: 2024-08-30 12:28:59

Div 滚动条滚动到指定的位置的相关文章

如何通过JQuery将DIV的滚动条滚动到指定的位置

这里有一个方法可以将DIV的滚动条滚动到其子元素所在的位置,方便自动定位. var container = $('div'), scrollTo = $('#row_8'); container.scrollTop( scrollTo.offset().top - container.offset().top + container.scrollTop() ); // Or you can animate the scrolling: container.animate({ scrollTop:

js将滚动条滚动到指定位置的方法

代码如下(主要是通过设置Location的hash属性): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <

tableView刷新指定的cell 或section和滚动到指定的位置

转自:http://blog.csdn.net/tianyou_code/article/details/54426494 //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; //一个cell刷新 NSIndexPath *index

DIV内滚动条滚动到指定位置

相对浏览器,将指定div滚到到指定位置,其用法如下: $("html,body").animate({scrollTop: $(obj).offset().top},speed); ps:obj是需要定位的对象,speed是滚动的速度 然而如果需要相对某一个容器(称之div1),将其内部的div2滚动到相对div1的指定位置,用法如下: $("div1").animate({scrollTop: $("div2").position().top}

jquery操作滚动条滚动到指定位置

<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $(".btn1").click(function(){ $("div").

滚动条滚动到指定位置

function scrollToCenter(){ var div = $("#canvas-wrap"); var top = (div[0].scrollHeight - div.height()) / 2; div[0].scrollTop = top; }

实现滚动条滚动到指定位置时,滑入显示某个元素

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin:0; padding:0; } .test{ margin:900px auto 500px; width:800px; height:600px; position: relati

JQuery控制滚动条滚动到指定位置

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <style> 7 .redMark{ 8 color: red; 9 font-weight: bold; 10 } 11 .blueMark{ 12 color: blue; 13 font-weight: bold; 14

点击滚动到指定元素位置

$(document).ready(function (){ $("#scroll").click(function (){ $('html, body').animate({ scrollTop: $("#div").offset().top }, 500); }); }); 使用scrollTop方法,加上一点延时动画(animate) 原文地址:https://www.cnblogs.com/wangyongx/p/10932253.html