Home >Web Front-end >JS Tutorial >javascript dom code application simple photo album [firefox only]_image special effects
But I think this is not enough. After all, everything is packaged by others. You have to learn the native javascript in depth to be practical. I saw a good blog post today, which introduced an example of a photo album based on js dom programming. Although this example is small, I personally think it is of great learning value. I will give the html and renderings first, which will help with the js later. understanding.
var insertedElement = parentElement.insertBefore(newElement, referenceElement);
insertedElement is actually newElement, as a return result
parentElement is the parent element to be inserted, that is, which element is inserted into
newElement is of course the new element to be inserted
referenceElement refers to the element before which
should be insertedWe then look at the prepareGallery function. Its function is to assign a click event to each a element. Return showPic(this) returns false by default in order to prevent the default behavior after clicking on the a element (directly to the new Picture displayed on the page)
The following is the core showPic function. By obtaining the href and title attribute values in the a element that wraps the corresponding small picture (the value of href is the path of the large picture corresponding to the small picture), it prepares the img generated in the preparePlaceholder function. Set the src attribute and the description text in p to form the final effect. There is a nodeType here, and the details can also be found in Mozilla developer center.
Finally, there is a very interesting function called addLoadEvent. It is very interesting... It has a recursive feeling. The event functions are added like a queue and then executed sequentially.
Haha, that’s all for the analysis of this photo album. This is my first blog post. If there is anything wrong or something that needs improvement, I hope fellow bloggers can give me some pointers. I will humbly accept it. Thank you.
Code package download