简体   繁体   English

从单击的div中心将弹出窗口缩放到中心屏幕

[英]Zoom pop-up to center screen from center of clicked div

I am new for jQuery and all, forgive me If I am wrong anywhere. 我是jQuery和其他所有人的新手,请原谅我是否在任何地方出错。

I have a requirement, that there are multiple click-able boxes, as soon as you click on any box it will open like pop-up but in such a manner It will look like it is coming out from that particular clicked box, and if you will close the opened pop-up, it will shrink to the clicked box(look like it is going inside the clicked box) 我的要求是,有多个可单击的框,一旦您单击任何框,它就会像弹出窗口一样打开,但是以这种方式看起来好像是从该特定的单击框中出来的,如果您将关闭打开的弹出窗口,它将缩小到被单击的框(看起来像在被单击的框内)

This is a bit of a complex question for a jQuery novice, but here is a solution. 对于jQuery新手来说,这是一个复杂的问题,但这是一个解决方案。

Caveat: In a rush and don't have time just now to calculate the correct coords to position the pop-up box dead center of screen - this example puts the top/left corner of the box dead center of screen. 注意:匆忙而又没有时间来计算正确的坐标,以将弹出框的死点定位在屏幕上- 此示例将上/左角放在屏幕的死点上。 I leave it to you to work out the coordinates to put center of box in center of screen -- and I would appreciate it if you would leave a comment with link to revised jsFiddle with your solution. 我将其留给您算出将框的中心置于屏幕中心的坐标- 如果您在解决方案中留下评论并链接到修订的jsFiddle,将不胜感激。

jsFiddle Demo jsFiddle演示

  var xx, yy, mPos = { x: -1, y: -1 }; //mouse position $(document).mousemove(function(event) { mPos.x = event.pageX; mPos.y = event.pageY; }); $('.dd').click(function(){ xx = mPos.x; yy = mPos.y; $('#msg').css({top:mPos.y+'px',left:mPos.x+'px'}).animate({ height: '400px', width: '500px', left: $(window).width() / 2, top: $(window).height() / 2 },500,function(){ //use a callback to show overlay ONLY when animation finished $('#overlay').show(); }); }); $('#msg').click(function(){ $('#overlay').hide(); $('#msg').animate({ height: '0px', width: '0px', left: xx+'px', top: yy+'px' },500); }); 
 #overlay{position:absolute;top:0;left:0;height:100%;width:100%;background:black;opacity:0.7;z-index:1;display:none;} #msg{position:absolute;height:0;left:0;background:wheat;overflow:hidden;z-index:2;} .dd{height:30px;width:100px;margin:30px;padding-top:25px;border:1px solid orange;} .clickable{cursor:pointer;} 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div id="overlay"></div> <div id="msg">Click on me to minimize again</div> <div id="d1" class="dd clickable">Div One</div> <div id="d2" class="dd clickable">Div Two</div> <div id="d3" class="dd clickable">Div Three</div> <div id="d4" class="dd clickable">Div Four</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM