0

jquery width(); に問題があります。

HTML マークアップ:

<img height="300px" src="http://localhost/portfolio/wp-content/uploads/Alone.jpg" alt="Alone" title="Alone" />

Jクエリ:

var slide_width = 0;
    $("#barely_slide article img").each(function(){
        console.dir($(this).width());
    });
    console.dir(slide_width);

見ると、$(this)clientWidth が正しい値を返し、offsetWidth も返されますが、これらには同等の jquery 関数がありません。

4

3 に答える 3

2

関数呼び出しを次のようにラップします。

(function($) {

  $(document).ready(function() {
    //Here you can manupilate the dom. Images are not loaded yet.
  });

  $(window).load(function() {
    //Here you can check for image widths.
  });

})(jQuery);

クライアントの幅は次の方法で確認できます。

$(window).width();

ドキュメントの幅は次のとおりです。

$(document).width();
于 2013-04-23T07:05:09.000 に答える
1

画像が読み込まれた後に幅を取得します。

$("#barely_slide article").on('load', 'img', function(){
    console.dir($(this).width());
});
于 2013-04-23T07:05:12.553 に答える