有谁能帮我解决这个问题吗。
我正在调整一些闪存对象/嵌入代码的大小,以适应使用jquery的浏览器窗口。请参阅下面的HTML。
<div id="prezi">
<object id="prezi_3453246342644353463435463456435" width="1000" height="800">
<embed width="1000" height="800" ></embed>
</object>
</div>JQUERY (此工作)
function preziresize() {
var $objectId = $('#prezi_3453246342644353463435463456435'),
$objectEmbed = $objectId.find('embed'),
windowWidth = $(window).width(),
windowHeight = $(window).height();
$objectId.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
$objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
}
$(document).ready(function() {
preziresize();
});
$(window).resize(function() {
preziresize();
});我的问题
但上面脚本的缺点是,我必须手动将对象的ID放入脚本中。:(
在我的新脚本上,它不起作用,我试图自动获取对象的id,并将其赋值为变量。请看下面我的功能。
function preziresize() {
var $objectId = $('#prezi').attr( 'id' ),
$objectEmbed = $objectId.find('embed'),
windowWidth = $(window).width(),
windowHeight = $(window).height();
$objectId.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
$objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
}任何指点都是非常感谢的。
乔希
发布于 2012-04-05 10:34:12
编辑:,您最好也在调整大小时执行它。
$(window).bind("resize.preziresize", function() {
$('div#prezi object')
.find('embed')
.andSelf()
.attr( 'height' , $(window).height() )
.attr( 'width' , $(window).width() );
}).trigger("resize.preziresize");发布于 2012-04-05 10:34:04
var $object = $('#prezi').find("object"),
$objectEmbed = $object.find('embed'),发布于 2012-04-05 10:36:57
这段代码没有多大意义,sinse $("#prezi")意味着您已经知道它是id,它是"prezi“。代码的另一个问题是,$objectId是一个字符串,而不是jQuery对象,因此不能在其上使用.find。试试这个:
function preziresize() {
var $object = $('#prezi object'),
$objectId = $object.attr('id')
$objectEmbed = $object.find('embed'),
windowWidth = $(window).width(),
windowHeight = $(window).height();
$object.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
$objectEmbed.attr( 'height' , windowHeight ).attr( 'width' , windowWidth );
}https://stackoverflow.com/questions/10026928
复制相似问题