Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7: Animations and Effects > Resizing Elements

RESIZING ELEMENTS

You might have expected a simple utility method for resizing an element but there isn’t one. The $.resize() method is a handler for the onresize event. Unless you’re using $.animate(), you’ll have to code your own.

To resize an element just change its height and width attributes using $.css(). For example, to shrink the width of an existing element you could do the following:

var w = $(“#myElem”).css(“width”);
w = parseInt(size.replace(“px”,””)) - 10;
$(“#myElem”).css(“width”, w-10);

But this has the inherent disadvantage of returning a string with a unit, for example, pixels. By using the $.height() and $.width() methods, you can get the height and width of an element, making it easier to resize:

var w = $(“#myElem).width() - 10;
$(“#myElem”).width(w);

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint