Javascript achieves image carousel effect (2) control of Image Sequence nodes and javascript nodes

Source: Internet
Author: User

Javascript achieves image carousel effect (2) control of Image Sequence nodes and javascript nodes

Recommended: Jquery code for image carousel (1)

In the previous article, we introduced how Javascript achieves image carousel (I) to beat the image. Here we implement the jump of the Image Sequence node. while redirecting an image, we generally need to know where it is redirected. Here, the image sequence node needs to be displayed along with the image. next we will analyze it directly.

We will show you the following information before you talk about the text:

In the HTML and CSS code structures, we need to add an image sequence to determine whether the selected style is used.

#slider ol li a.active{background-color: #ffffff;color: #ff0000;}

In JS code, we need to make some changes and additions to the JS Code in the previous article. The first thing we need to change here is to encapsulate the code to be redirected and encapsulate it into a method, then return the value of setInterval. this mainly implements some functions for the sequence node.

Then, in the jump code, change the corresponding sequence node style to display the jump position.

// Image node var slider = document. getElementById ("slider"); var imgul = slider. getElementsByTagName ("ul") [0]; var imglis = imgul. getElementsByTagName ("li"); var len = imglis. length; // Image Sequence node var numol = slider. getElementsByTagName ("ol") [0]; var numlinks = numol. getElementsByTagName ("a"); // shared sequence var index = 0; // image jump. When the image jumps, you can change the jump of the sequence node to var jump = function () {return setInterval (function () {if (index> = len) {index = 0 ;}// the image jumps to imgul. style. left =-(800 * index) + "px"; // change the sequence node style: first, clear the style of all links, then, the corresponding sequence node style for (var I = 0; I <len; I ++) {numlinks [I] is activated. setAttribute ("class", "");} numlinks [index]. setAttribute ("class", "active"); index ++;}, 2000) ;}; var jumpindex = jump ();

You also need to add the hover State control of the sequence node.

After the hover, the image jump should be stopped. The images that should stay under the hover should be displayed. The number of sequence nodes corresponds to the number of images, therefore, you can change other States by the position of the current sequence node.

When the mouse leaves the sequence node, the image should be automatically redirected.

// Add hover Control for sequence nodes: 1. after hover, you must disable the image jump and display it on the current image. here you need to clear the jump 2. after hover leaves, jump to the current image for (var I = 0; I <len; I ++) {// hovernumlinks [I]. onmouseover = function () {clearInterval (jumpindex); for (var I = 0; I <len; I ++) {numlinks [I]. setAttribute ("class", ""); if (numlinks [I] === this) {index = I ;}} imgul. style. left =-(800 * index) + "px"; numlinks [index]. setAttribute ("class", "active");} // outnumlinks [I]. onmouseout = function () {jumpindex = jump ();}}

In this way, we have completed the effect of step 2. All the descriptions in this article have been completed and hope to help you.

Articles you may be interested in:
  • Js image carousel (5 images)
  • Code for Implementing Image carousel using native javascript
  • JS simple carousel image scrolling instance
  • JS Code with left and right arrows for image carousel
  • Simple js image rotation code (js image rotation)
  • Js Image Automatic carousel code sharing (js image carousel)
  • JS method for achieving simple image carousel Effect
  • Native js and jquery achieve image carousel Special Effects
  • Manual Switch of js image carousel
  • Javascript achieves image carousel effect (1) to make the image beat
  • Javascript achieves image carousel effect (2) control of Image Sequence nodes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.