Я написал эту функцию:
/**
* resize_embedded resizes embedded videos like youtube videos;
* Examples:
* - resize_embedded($('youtube_div'), 300, 200);
* - Fiddle: http://jsfiddle.net/xjxVC/1
*
* Parameters:
* @param jquery the element that contains the embedded media
* @param number the new width
* @param number the new height
*
*/
function resize_embedded(){
// Did we receive 3 correct parameters
if(arguments.length === 3 && $(arguments[0]).length && isNumber(arguments[1]) && isNumber(arguments[2]))
;
else
return 0;
// Clone embedded element
$c = $(arguments[0]).clone();
// Resize clone (replace width/height of all children who have them)
$c
.attr('width', arguments[1])
.attr('height', arguments[2])
.children().each(function(){
$(this).attr('width') && $(this).attr('width', arguments[1]);
$(this).attr('height') && $(this).attr('height', arguments[2]);
})
// Replace target with clone
$(arguments[0]).replaceWith($c);
}
function isNumber(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}
Демо: http://jsfiddle.net/xjxVC/1