2017-10-12 34 views
2

例如,如果我有如何在jQuery中獲取當前查詢的元素?

<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> 

現在我做了

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" 
    }); 
}); 

我如何獲得每個$('.fr-box-wrapper')的寬度和高度?

+0

你想在這裏實現什麼。這是什麼? –

+0

您好aero您想獲得每個$('。fr-box-wrapper')的寬度和高度,或者您想獲取特定的單擊元素高度和寬度? – Kannan

回答

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" 
    }); 
});