How to get currently queried elements in jQuery?

时间:2017-10-12 09:42:10

标签: jquery css

for example if I have

<img class="fr-box-wrapper"></img>
<img class="fr-box-wrapper"></img>
<img class="fr-box-wrapper"></img>
<img class="fr-box-wrapper"></img>
<img class="fr-box-wrapper"></img>
<img class="fr-box-wrapper"></img>

now I do a

this.magnify.click(function(e){
  $('.fr-box-wrapper').attr({
    "origwidth": $(this).width(), // this is wrong
    "origheight": $(this).height() // this is wrong
  }).css({
    position: "fixed",
    top: "0",
    left: "0",
    width: $(document).width(),
    height: $(document).height(),
    background: "white",
    overflow: "auto"
  });
});

how do I get width and height of each $('.fr-box-wrapper')?

1 个答案:

答案 0 :(得分:2)

$('.fr-box-wrapper').each(function(){
  $(this).attr({
    "origwidth": $(this).width(),
    "origheight": $(this).height()
  }).css({
    position: "fixed",
    top: "0",
    left: "0",
    width: $(document).width(),
    height: $(document).height(),
    background: "white",
    overflow: "auto"
  });
});