Hey Guys。 これは本当に難しい質問ではなく、私がJSを知らないことです。jQueryでJavaScriptの戻り値を使用する
jQueryからイメージのサイズを変更するために呼び出すことのできるJSの小さな関数を作成しようとしています。 JS関数を実行した後、値をjQueryに戻す方法がわかりません。あなたが見ることができるように、私はいくつかの値にフィードバックnew_widthとnew_height取得しようとしている
$('a').click(function() {
var slideshowHeight = $(this).closest('.stage').css('height')
var slideshowWidth = $(this).closest('.stage').css('width')
var newImageHeight = $(this).attr('data-height')
var newImageWidth = $(this).attr('data-width')
fit_within_box(slideshowWidth, slideshowHeight, newImageWidth, newImageHeight);
$(this).children('img').css('width',new_width);
$(this).children('img').css('width',new_height);
}
function fit_within_box(box_width, box_height, width, height)
{
var new_width = width
var new_height = height
var aspect_ratio = parseInt(width)/parseInt(height)
if (new_width > box_width)
{
new_width = box_width
new_height = int(new_width/aspect_ratio)
}
if (new_height > box_height)
{
new_height = box_height
new_width = int(new_height * aspect_ratio)
}
return (new_width, new_height)
}
:ここで私はこれまで持っているものです。
ありがとうございました!
これはJSONオブジェクトではなく、オブジェクトリテラルです。 – alex