تصف هذه المقالة طريقة الحد من حجم عرض الصورة في JavaScript. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
/*** الحد من حجم عرض الصورة. ** param thisobj مكون الصورة* param limit limit حجم العرض* param limith حد حجم الارتفاع*/وظيفة التصور (thisobj ، limitw ، limith) {var neww ؛ فار نيوه ؛ if (thisobj.width> limitw) {neww = limitw ؛ newh = parseint (thisobj.height * neww / thisobj.width) ؛ // Scale by width if (newh> limith) {newh = limith ؛ neww = parseint (thisobj.width * newh / thisobj.height) ؛ } thisobj.width = neww ؛ thisobj.height = newh ؛ } آخر إذا (thisobj.height> limith) {newh = limith ؛ neww = parseint (thisobj.width * newh / thisobj.height) ؛ thisobj.width = neww ؛ thisobj.height = newh ؛ }}آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.