87,899
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
</head>
<body>
<div id="title" style="width:100px;height:30px;line-height:30px;text-align:center;border:#aaa solid 1px;background-color:#f5f5f5;"></div><br />
child index :<input type="text" id="index" style='width:40px;'> <button onclick="fun1()">get top (offset , postion)</button><br /><br />
<div id="con" style="width:420px;height:500px;border:#aaa solid 1px;overflow-y:scroll;"></div>
<script>
for(var i=0;i<10;++i){
$("#con").append("<div style='width:380px;height:198px;border:#00f dotted 1px;margin-left:8px;background-color:#f5f5f5;'>"+i+"</div>");
}
function fun1()
{
$("#title").text($("#con").children().eq(parseInt($("#index").val())).offset().top+","+$("#con").children().eq(parseInt($("#index").val())).position().top);
}
</script>
</body>
</html>