如何自动将div对齐到文档上的标签

时间:2022-11-24 23:00:30

i have a div i.e

我有一个div

<div id="data_sprite">Jquery ajax data here</div>

and it is invisible....

它是看不见的....

now suppose i have my first <a> tag on top of document and 2nd <a> tag on bottom of document... now what i want is that if i click on <a> on top of page the div auto align with its top right corner and when i click on <a> at bottom the div should auto align with its top right corner how can i achieve that with jquery or what ever....

现在假设我在文档顶部有第一个标签,在文档底部有第二个标签...现在我想要的是,如果我点击页面顶部的,div会自动调整右上角,当我点击底部的时,div应该自动对齐它的右上角我怎么能用jquery或者什么来实现....

1 个解决方案

#1


2  

With JQuery, you can try something like that, assuming ajaxlink is a class used for both your tags:

使用JQuery,您可以尝试类似的东西,假设ajaxlink是用于两个标记的类:

$('.ajaxlink').click(function() {
  var position = $(this).offset();
  position.left = position.left + $(this).width() - $('#data_sprite').width();
  position.top = position.top + $(this).height();
  $('#data_sprite').css(position)
});

#1


2  

With JQuery, you can try something like that, assuming ajaxlink is a class used for both your tags:

使用JQuery,您可以尝试类似的东西,假设ajaxlink是用于两个标记的类:

$('.ajaxlink').click(function() {
  var position = $(this).offset();
  position.left = position.left + $(this).width() - $('#data_sprite').width();
  position.top = position.top + $(this).height();
  $('#data_sprite').css(position)
});