用jQuery除以css计算的宽度而不是元素的width属性 [英] divide by css calculated width instead of element width attribute with jQuery
本文介绍了用jQuery除以css计算的宽度而不是元素的width属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有以下代码:
$('.blogimages img').css('marginLeft', function() {
return - $(this).width()/2;
});
但是,它采用的是width="750"
属性,而不是使用样式表新计算出的属性.
However it's taking the width="750"
attribute instead of the newly calculated with my stylesheet has given it.
图像设置示例:
<div class="img-wrap" style="position: relative; ">
<img class="insert-all wide" title="23" src="http://www.threefishfiesta.com/wp-content/uploads/2012/08/231.jpeg" alt="" width="750" height="500">
</div>
CSS:
.client-small .img-wrap {
width: 200px;
height: 200px;
overflow: hidden;
text-align: center;
}
.img-wrap .wide{
height: 100%;
width: auto;
}
.img-wrap .tall{
width: 100%;
height: auto;
}
有没有一种方法可以重写此格式,使其采用css生成的宽度而不是html属性的宽度?
Is there a way to rewrite this to take the css generated width instead of the html attribute width?
谢谢!
推荐答案
您是否尝试过获取css值? $(this).css('width')/2;
Have you tried getting the css value? $(this).css('width')/2;
这篇关于用jQuery除以css计算的宽度而不是元素的width属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文