Book Image

jQuery UI 1.10: The User Interface Library for jQuery - Fourth Edition

Book Image

jQuery UI 1.10: The User Interface Library for jQuery - Fourth Edition

Overview of this book

jQuery UI, the official UI widget library for jQuery, gives you a solid platform on which to build rich and engaging interfaces quickly, with maximum compatibility, stability, and effort. jQuery UI's ready-made widgets help to reduce the amount of code that you need to write to take a project from conception to completion. jQuery UI 1.10: The User Interface Library for jQuery has been specially revised for Version 1.10 of jQuery UI. It is written to maximize your experience with the library by breaking down each component and walking you through examples that progressively build up your knowledge, taking you from beginner to advanced user in a series of easy-to-follow steps. Throughout the book, you'll learn how to create a basic implementation of each component, then customize and configure the components to tailor them to your application. Each chapter will also show you the custom events fired by the components covered and how these events can be intercepted and acted upon to bring out the best of the library. We will then go on to cover the use of visually engaging, highly configurable user interface widgets. At the end of this book, we'll look at the functioning of all of the UI effects available in the jQuery UI library.
Table of Contents (22 chapters)
jQuery UI 1.10: The User Interface Library for jQuery
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Positioning with a function


We can set the using option to a function, and position the positioned element manually. Change the configuration so that it appears as follows:

$(".ui-positioned-element").position({
  of: ".ui-positioning-element",
  my: "right bottom",
  at: "right bottom",
  using: function(pos) {
    $(this).css({
      backgroundColor: "#fc7676",
      top: pos.top,
      left: pos.left
    });
  }
});

Save this change as positionFunction.html. We supply an anonymous function as the value of the using option. This function is passed as a single argument that is an object containing the properties top and left, which correspond to the values that the element we are positioning should be given.

As you can see from this code, we still need to position the element manually, but the function allows us to do any preprocessing of the element that may be required. Within the function, the this object is set to the element being positioned.