1

私は現在、このコードを持っています:

$('.blogimages img').css('marginLeft', function() { 
    return - $(this).width()/2;
});

ただしwidth="750"、スタイルシートで新しく計算された属性の代わりに属性を取得しています。

画像設定例:

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

これを書き直して、html 属性の幅の代わりに CSS で生成された幅を取る方法はありますか?

ありがとう!

4

2 に答える 2

0

CSS値を取得しようとしましたか?$(this).css('width')/2;

于 2012-08-31T00:40:55.990 に答える
0

あなたはouterWidth()を使用することができます - http://api.jquery.com/outerWidth/

于 2012-08-31T00:40:10.577 に答える