jquery

2016-04-11 3 views
0

ile bir kılavuz görünümün resmini yeniden boyutlandırın JQuery'de yeni ve bir yere takıldım. Bir kılavuz görünümüm var ve içinde bir resim sütunu var. Bu görüntüleri yeniden boyutlandırmayı deneyin, ancak gerçekten anlayamıyorum. Bu kodu denedim ve görüntüler bir gridview'de olmadığında iyi çalışıyor, ancak bir gridview içinde çalışmam gerektiğini söylediğim gibi. İşte jquery

benim ızgara geçerli: Burada

<asp:GridView ID="GridViewFuel" AutoGenerateColumns="false" CssClass="mGrid" runat="server" DataSourceID="EntityDataSourceFuels"> 
    <Columns> 
     <asp:TemplateField HeaderText="Sürücü"> 
      <ItemTemplate> 
       <%#GetDriverNameAndSurname(Convert.ToInt16(Eval("DriverId"))) %> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Araç"> 
      <ItemTemplate> 
       <%#GetCarPlate(Convert.ToInt16(Eval("CarId"))) %> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Fiş"> 
      <ItemTemplate> 
       <asp:Image ID="Image1" ImageUrl='<%#Eval("FuelPrice") %>' runat="server" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

Ve benim jquery geçerli:

$(document).ready(function() { 
     $('.mGrid img').each(function() { 
      var maxWidth = 151; // Max width for the image 
      var maxHeight = 151; // Max height for the image 
      var ratio = 0; // Used for aspect ratio 
      var width = $(this).width(); // Current image width 
      var height = $(this).height(); // Current image height 

      // Check if the current width is larger than the max 
      if (width > maxWidth) { 
       ratio = maxWidth/width; // get ratio for scaling image 
       $(this).css("width", maxWidth); // Set new width 
       $(this).css("height", height * ratio); // Scale height based on ratio 
       height = height * ratio; // Reset height to match scaled image 
       width = width * ratio; // Reset width to match scaled image 
      } 

      // Check if current height is larger than max 
      if (height > maxHeight) { 
       ratio = maxHeight/height; // get ratio for scaling image 
       $(this).css("height", maxHeight); // Set new height 
       $(this).css("width", width * ratio); // Scale width based on ratio 
       width = width * ratio; // Reset width to match scaled image 
      } 
     }); 
    }); 

Nasıl bu benim GRIDVIEW ile çalışmak yapabilir?

cevap

0

Her hücreye döngü yapmayı denerim. Bir resim varsa o zaman oranını yap.

$ ('mGrid tr'). Each (function() {

$('td', this).each(function() { 

    //check if image exists 

}); 

})

+0

Dilemelisin nasıl göstersek çok harika olurdu böylece jquery yeniyim dediğim gibi Görüntü mü yoksa kontrol edilsin mi? –

+0

Her hücreden geçtikten sonra, bir görüntünün olup olmadığını kontrol etmeniz gerekir. Kendim test etmedim ama aşağıdaki gibi bir şey olmalı: var img = $ (this) .find ('img'); eğer (img.length>) {// img'ye oranı yap – plottydotty