0

画面サイズが変更されたときに (css ファイルで) 画像に異なる変換属性を作成したため (@media screen.. {} で同じように見えるため)、元のサイズではなく現在のサイズから画像のサイズを変更しようとしています。さまざまなサイズの画面で)。

//..this is only part of a code of a jslider..

callback: function( value ){
    var SliderValue = $('#SliderSingle2').attr('value');
    if(value== "2003"){                         
        //intresting part here:
        var currentSize = $("#img").css('transform');
        var currentSize = parseFloat(currentSize)*1.2;
        $("#img").css('transform', currentSize);
        alert(currentSize);
    }
}

//...that alert returns now NaN so parseFloat can't read 
//transform:scale(0.6) attribute.. but there isn't parseDouble option.. 
//Any succestions??

私がやろうとしているのはこれです:(リンク)フォントではなく画像のみ..

4

2 に答える 2

0

アラートで NaN 値を取得する理由は次のとおりです。

var currentSize = $('#img').css('transform'); //Returns a string. Example: "matrix(a,b,c,d,tx,ty)"
parseFloat(currentSize); // NaN

詳細はこちら: MDN の CSS 変換

返された行列を使用可能な値に変換するために必要な計算を行う必要があります。次に、調整された値を jQuery CSS メソッドに戻します。別のオプションは、次のようなことを試すことです。

var imgWidth = Math.round($('#img').css('width').replace('px','')*1.2),
    imgHeight = Math.round($('#img').css('height').replace('px','')*1.2);

$('#img').css({ width:imgWidth, height:imgHeight });

お役に立てれば。

于 2013-05-30T07:43:30.480 に答える