jQuery add event
The following jQuery code adds an event by calling a function scroll_position
jQuery.event.add(window, "scroll", scroll_position);
function scroll_position() {
var p = jQuery(window).scrollTop();
jQuery(scrollbox).css('position',((p+10)>start) ? 'fixed' : 'absolute');
jQuery(scrollbox).css('top',((p+10)>start) ? '10px' : '');
}
Is it possi开发者_运维百科ble to add this event without using the function scroll_position? I mean, I just want to do same thing without using a function. (I dont have any reason for not using the function, just learning the jQuery).
What do you need a event for when you do not want to do anything with it?
You can do inline functions, e.g.
jQuery.event.add(window, "scroll", function() {
alert("magic happens here");
});
thus ridding yourself of the need of a function of your own...
Simply bind the event hung .bind or .live and then trigger it whenever you wany using .trigger
No need for jQuery.event.add
精彩评论