<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'move.jsp' starting page</title>
<script type="text/javascript" src="script/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function(){
$("#show1").click(function(){
$("#showdiv1").css({top:($(window).height()-100)/2+$(window).scrollTop()+'px',left:($(window).width()-300)/2+document.documentElement.scrollLeft+'px'});
$("#showdiv1").show();
$("#showdiv2").hide();
return false;
});
var menuYloc = $("#showdiv1").offset().top;
$(window).scroll(function (){
var offsetTop = menuYloc + $(window).scrollTop();
$("#showdiv1").animate({top : (offsetTop+($(window).height()-100)/2 )+"px"},{ duration:600 , queue:false });
});
//
$("#show2").click(function(){
$("#showdiv2").css({top:($(window).height()-100)/2+$(window).scrollTop()+'px',left:($(window).width()-300)/2+document.documentElement.scrollLeft+'px'});
$("#showdiv2").show();
$("#showdiv1").hide();
return false;
});
$("#showdiv2").mousedown(function(e)//e鼠标事件
{
$(this).css("cursor","move");//改变鼠标指针的形状 为移动
var offset = $(this).offset();//DIV在页面的位置
var x = e.pageX - offset.left;//获得鼠标指针离DIV元素左边界的距离
var y = e.pageY - offset.top;//获得鼠标指针离DIV元素上边界的距离
$(document).bind("mousemove",function(ev)//绑定鼠标的移动事件,因为光标在DIV元素外面也要有效果,所以要用doucment的事件,而不用DIV元素的事件
{
$("#showdiv2").stop();//加上这个之后
var _x = ev.pageX - x;//获得层X方向的值ev.pageX为鼠标的坐标
var _y = ev.pageY - y;//获得层Y方向的值
$("#showdiv2").animate({left:_x+"px",top:_y+"px"},10);
});
});
$(document).mouseup(function()
{
$("#showdiv2").css("cursor","default");
$(this).unbind("mousemove");
})
});
</script>
</head>
<body>
<h3><a href="kuang.jsp">go</a></h3>
<h3><a href="#" id="show1"> 弹出居中的自动Move的层</a></h3>
<h3><a href="#" id="show2"> 弹出居中的手动Move的层</a></h3>
<!-- 显现层 -->
<div id="showdiv1" style="z-index: 1000;width: 300px;height: 100px;background-color: blue;position: absolute;display: none "><iframe name="test" src="/index.jsp"></iframe></div>
<div id="showdiv2" style="z-index: 1000;width: 300px;height: 100px;background-color: blue;position: absolute;display: none "></div>
<div style="z-index: 100;width: 900px;height: 900px; "></div>
</body>
</html>