jquery - Javascript Double-Click Element -


O People .. Quick Question:

I wrote a simple JS, to see that image To open a light box, click on an image link. Actually, using jQuery (yes, I was lazy), I find out the clicks of an anchor tag, use a regex to make sure that The HREF feature is in an image file, and if it is, it opens the image in the lightbox. All this works well except for one task: the anchor needs to be clicked twice before. Why is it like this?

Here's the script I wrote:

  $ (document) .ready (function () {var href; var imageExtensions = / (.) + (.jpg) | (.png) | (.gif) | (.bmp) /; // Click any link $ ("a") live ("click", function (event) {href = $ (this). Attr ("href"); // If the target URL is an image, use the lightbox to open it if (imageExtensions.test (href) {event.preventDefault (); $ (this) .attr ("class "," LightboxIMG "); // Open the lightbox, and open $ Lightbox (" LightboxIMG "). LightBox (); $ (this) .attr (" class "," ");}}); // End    });  

I do not know what might be the reason of clicking the user twice to activate the publisher if you want a pattern of what I'm talking about, Using a script in beta of the new website:

See what I'm saying to see "full size" I appreciate much help - Thank you very much!

I guess what's happening lightbox () < / Code> The call sets anchor only for the anchor, it does not actually display the lightbox, therefore, the first click is telling the lightbox "Make it a lightbox link" and the second click is caught by the lightbox and in fact the lightbox Shows

Edit is a live aspect, is it important? Or, are you planning to add more links, which will require you to capture documents when loading? If the live is not required, the standard lightbox () method should suffice to capture clicks. If this is the case, I would consider writing a hook anchor () style method that you can call after an azxing which just calls lightbox () . Something like this:

  $ (document) .ready (function () {hookheckers ();}); Function hook anchors () {var imageExtensions = /(.)+(.jpg)|(.png)|(.gif)|(.bmp)/; $ ('A'). Filter (function () {return image extension.Test ($ (this) .attr ("href"))} .lightbox (); }  

In this way, you can call the hook anchors (for example, as a result of get $ ) inside the code while changing your dome.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -