滑动定位对应项

1、源码

<!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=utf-8" />
<title></title>


<!--   引入jQuery -->
<script src="scripts/jquery.js" type="text/javascript"></script>


<script type="text/javascript">
$(function(){
	//为圆圈定位:1、先获取虚线的左坐标;2、获取虚线的宽度;3、设置圆圈的left值
	var rx=$("#innerright").position().left;
	var rw=$("#innerright").outerWidth(true);
	var setx=rx+rw-20;
	$("#circle").css("left",setx);
	//初始化圆圈的top
	var $first=$(".out .innerleft div:first");
	showHeight($first);	
});
var showHeight=function(obj){
	var rt=$(obj).position().top;
	var rtdivh=$(obj).outerHeight(true);
	var seth=rt+rtdivh/2-10;
	//$("#circle").css({"top":seth});//没有动画效果
	$("#circle").animate({top:seth},"slow");//带有动画的滑动显示
}
</script>
<style type="text/css">
body {
	font: normal 12px/17px Arial;
	margin:0px;
	padding:0px;
}
.out{width:600px;height:600px;margin:2% auto;border:1px solid green;padding:2%;position:relative;}
.innerleft{width:60%;height:100%;margin:2%;padding:1%;float:left;}
.out .innerleft div{width:90%;height:15%;max-height:80px;line-height:80px;margin:2%;border:1px dashed green;text-align:center;font-size:20px;}
.out .innerleft div:hover{background:green;}
.innerright{width:10%;height:100%;border-right:1px dashed green;margin:10px;float:left;}
.circle{width:20px;height:20px;border-radius:50%;background:#F69;position:absolute;}
</style>
</head>
<body>


<div class="out">
	<div class="innerleft">
	<div onclick="showHeight(this)">No1</div>
    	<div onclick="showHeight(this)">No2</div>
    	<div onclick="showHeight(this)">No3</div>
    	<div onclick="showHeight(this)">No4</div>
    	<div onclick="showHeight(this)">No5</div>
    </div>
    <div id="innerright"  class="innerright"></div>
    <div id="circle" class="circle"></div>
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/LzzMandy/article/details/80930574