Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.17 MB, 49 trang )
Sorting
You should find when you run the page that you can move the boxes around,
close your browser, run the page again, and see the boxes retain the order that
you gave them:
Please note that that example does not run correctly in Opera and exhibits the same
unusual placement of sorted items that occurred in some of the earlier connected-list
examples in the chapter.
[ 372 ]
Chapter 11
Summary
We've finished off our tour of the interaction components of the library by looking
at the sortables component. Like the other modules that we looked at before, it has
a wide range of properties and methods that allow us to configure and control its
behavior and appearance in both simple and more complex implementations.
We started the chapter off with a look at a simple, default implementation with no
configuration to see the most basic level of functionality added by the component.
We looked at some of the different elements that can be made sortable and added
some basic styling to the page.
Following this, we looked at the range of configurable properties that are exposed by
the sortable API. The list is extensive and provides a wide range of functionality that
can be enabled or disabled with ease.
We moved on to look at the extensive event model used by this component which
gives us the ability to react to different events as they occur in any sort operation
initiated by the visitor.
Connected lists offer the ability to be able to exchange sortable items, giving our
Only one of these buttons will take you to the next page,
choose wisely (click the hint button for help).
<button id="Hint">Hint</button>
</body>
</html>
[ 381 ]
UI Effects
Save this as highlight.html. The code which invokes the highlight effect takes the
same familiar form as other library components. The effect constructor is called
and the actual effect is specified as a string argument in the constructor. View the
example and click the Hint button. The third button should briefly be highlighted:
The library files we needed for this example are listed below:
•
jquery-1.2.6.js
•
effects.core.js
•
effects.highlight.js
While our example may seem a little contrived, it is easy to see the potential for this
effect as an assistance tool on the front-end. Whenever there is a sequence of actions
that needs to be completed in a specific order, the highlight effect can instantly give
the visitor a visual cue as to the step that needs to be completed next. Similarly, it
could be used in a tutorial or electronic manual to draw attention to a particular
").text("That was the highlight").appendTo("body");
});
});
});
</script>
Save this as highlightParameter.html. Perhaps the most striking feature of our
new code is the empty object passed as the second argument. In this example, we
don't need any additional configurable properties, but we still need to pass in the
empty object in order to access the third and fourth arguments.
The highlight effect has only one configurable property that can be used in the
configuration object passed and that is the highlight color.
The animation should now proceed much slower as we have set the duration to
2000 milliseconds (2 seconds). Note that this third parameter may also take a string
representing the speed of the animation. Our callback function, passed as the fourth
and final argument, is perhaps the least useful callback in the history of JavaScript,
but it does serve to illustrate how easy it is to arrange additional post-animation code
execution. Here's how the page should look after the Hint button has been clicked:
[ 383 ]
UI Effects
Bouncing
Another simple effect we can use with little configuration is the bounce effect. To see
this effect in action create the following page:
BFG GTX 280 OC
1GB GDDR3 Dual DVI HDTV Out PCI-E Graphics Card
Cost:
$350
Basket total: <span id="total">0</span>