gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:11:17 25 4
gpt4 key购买 nike

我是 jQuery 的新手,如果我有任何错误,请原谅我。

我有一个要求,有多个可点击的框,只要你点击任何一个框,它就会像弹出窗口一样打开,但以这种方式它看起来像是从那个特定的点击框出来的, 如果你关闭打开的弹出窗口,它会缩小到点击框(看起来它正在进入点击框内)

最佳答案

对于 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 Demo

 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>

关于jquery - 从单击的 div 中心缩放弹出窗口到中心屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29145391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com