[英]jquery - make a div appear where I click?
Hey, I'm trying to make a little feature where I can click on an icon, and a box will appear that is similar to lightbox, but anchored on the icon. 嘿,我正在尝试制作一个小功能,我可以点击一个图标,然后会出现一个类似于灯箱的框,但是它固定在图标上。 Is there a way to
有办法吗?
Thanks! 谢谢!
// 1.Tell where the icon is on the screen
var off = $("#iconId").offset();
// 2.Have the top left corner of my box placed where the icon is
var div = $("#divId");
div.css({ position: "absolute", top: off.top, left: off.left });
// 3.Have my box appear in that location?
div.show();
$(function() {
$("#icon").click(function(){
var offset = $(this).offset();
$("#pop").css("position","absolute").css("top",offset.top+$(this).height()).css("left",offset.left);
$("#pop").show();
});
});
offset gets you the position of your icon and then you use those values to set the top and left offsets for your popup offset会使您获得图标的位置,然后使用这些值为弹出窗口设置顶部和左侧偏移
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.