jquery-events

How to wait for the 'end' of 'resize' event and only then perform an action?

南笙酒味 提交于 2019-11-25 23:17:36
问题 So I currently use something like: $(window).resize(function(){resizedw();}); But this gets called many times while resizing process goes on. Is it possible to catch an event when it ends? 回答1: I had luck with the following recommendation: http://forum.jquery.com/topic/the-resizeend-event Here's the code so you don't have to dig through his post's link & source: var rtime; var timeout = false; var delta = 200; $(window).resize(function() { rtime = new Date(); if (timeout === false) { timeout

Direct vs. Delegated - jQuery .on()

一世执手 提交于 2019-11-25 22:54:38
问题 I am trying to understand this particular difference between the direct and delegated event handlers using the jQuery .on() method. Specifically, the last sentence in this paragraph: When a selector is provided, the event handler is referred to as delegated . The handler is not called when the event occurs directly on the bound element, but only for descendants (inner elements) that match the selector. jQuery bubbles the event from the event target up to the element where the handler is

jQuery multiple events to trigger the same function

守給你的承諾、 提交于 2019-11-25 22:41:16
问题 Is there a way to have keyup , keypress , blur , and change events call the same function in one line or do I have to do them separately? The problem I have is that I need to validate some data with a db lookup and would like to make sure validation is not missed in any case, whether it is typed or pasted into the box. 回答1: You can use .on() to bind a function to multiple events: $('#element').on('keyup keypress blur change', function(e) { // e.type is the type of event fired }); Or just pass

Check if an image is loaded (no errors) with jQuery

放肆的年华 提交于 2019-11-25 21:51:54
问题 I\'m using JavaScript with the jQuery library to manipulate image thumbnails contained in a unordered list. When the image is loaded it does one thing, when an error occurs it does something else. I\'m using jQuery load() and error() methods as events. After these events I check the image DOM element for the .complete to make sure the image wasn\'t already loaded before jQuery could register the events. It works correctly except when an error occurs before jQuery can register the events. The

jQuery callback on image load (even when the image is cached)

社会主义新天地 提交于 2019-11-25 21:43:36
问题 I want to do: $(\"img\").bind(\'load\', function() { // do stuff }); But the load event doesn\'t fire when the image is loaded from cache. The jQuery docs suggest a plugin to fix this, but it doesn\'t work 回答1: If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete , like this: $("img").one("load", function() { // do stuff }).each(function() {