0

Can any one please help me solve this.

I am resizing some flash object/embed code to fit the browser window using jquery. Please see HTML below.

HTML

<div id="prezi">

     <object id="prezi_3453246342644353463435463456435" width="1000" height="800">

          <embed width="1000" height="800" ></embed>

     </object>

</div>

JQUERY (THIS WORKS)

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();

});


MY PROBLEM

But the downfall of the script above, is that I have to manually put the ID of my object into my script. :(

On my new script, which is not working, I am trying to automatically get the id of the object, and assign it as a variable. Please see my function below.

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 ); 

}


Any pointers would be great thanks.

Josh

0

3 Answers 3

3

Edit: You should better execute it on resize too.

$(window).bind("resize.preziresize", function() {
   $('div#prezi object')
       .find('embed')
       .andSelf()
       .attr( 'height' , $(window).height() )
       .attr( 'width' , $(window).width() );
}).trigger("resize.preziresize");
Sign up to request clarification or add additional context in comments.

2 Comments

WOW - this is alot simpler, great way of thinking! Though how would I get this to work on document ready too? Only works on window resize. Thanks
Hmmmm, I added this code into my document, but only works on window resize. If I wrap your code in document ready then it works -
2
var $object =     $('#prezi').find("object"),
    $objectEmbed =  $object.find('embed'),

1 Comment

Thank you this worked great, don't know why I didn't do this. :-)
-1

This code doesn't make much sense, sinse $("#prezi") means you already know it's id, it's "prezi". the other problem with your code is that $objectId is a string and not the jQuery object, so you can't use .find on it. Try this:

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 ); 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.