The InternetWeb design

JQuery Library: sliders for your site

Over time and the development of technologies in the field of web design are changing and the needs / requirements of users to the content of sites. If earlier it was mainly text content with a small number of thematic images, today the graphic component is the predominant one. It allows you to get the maximum amount of useful and useful information in a short time, and do not waste time reading long texts. In this regard, more and more popular and, moreover, an essential element of web pages are the sliders. They are blocks with varying content in them - from images to links. A modern way to add this web object is to use the jQuery library. Sliders created with the help of this tool are convenient, easy to use, and look very impressive. Next, we'll look at how to make these elements of a web page yourself. Thanks to a fairly large number of standardized tools, it becomes possible to implement jQuery sliders of various types and diverse content.

How to add a slider to a web page?

There are several ways of adding sliders to the site page . Often, you do not even have to write HTML code and go into the script. There are a lot of free libraries that offer users already ready templates, which allow adding jQuery sliders to your site. All that is required of you is to copy it to the source code of your web page and enjoy the result. However, in this case, the possibilities of realizing your creative fantasies are limited. Therefore, it will be superfluous to be able to create this design element yourself. To do this, you need to know how to implement a simple jQuery slider, and you can always complicate it by adding additional elements to the code.

Create a slider yourself: the code in HTML

The first thing to start with is to register the layout of the future slider.

  1. Create a Slideshow block in the HTML file, which will contain all our slides (pictures, etc.).
  2. In it we put a list of ul, each item of which will store a separate slide.

Working in CSS

Next, apply to it the necessary characteristics of the style, using a CSS document. It is necessary that the JQuery content slider we created works correctly and has the required look. At this stage, we have the following tasks:

  • To make the Slideshow block display only one, the currently needed slide (picture or content), and the rest were hidden;
  • Arrange slides one after the other (from left to right);
  • Make the ul-container in which the slides are stored, movable (left and right).

To do this, we set the following parameters in the CSS file:

  • For Slideshow: overflow-x - scroll, overflow-y - hidden:
  • For ul: float - left.

You can also set the width, height, background,

We write code in jQuery

In HTML and CSS, all necessary changes have been made. It remains for the code for jQuery, the sliders in which should have the following parameters:

  • Slides should change each other with a certain interval of time;
  • When you hover your mouse cursor, their movement should stop.

To do this, declare two variables: slidewidth (equal to the length of the slide) and slidertime (specifies the period of the slide change). The timer will be started when the page of the site is fully loaded. To this parameter we tie the action of hovering the mouse cursor on the slide (which stops the slide change).

Be sure to specify the length of the container ul. It will be equal to the number of slides multiplied by the length of each slide.

We paste the function responsible for changing the slides. That's all, you can check the work of your slider.

Conclusion

In this article, we discussed how to create jQuery sliders on your own. Using an example of a simple slider implementation, you can create your own variations of its interpretation, making appropriate changes to the source code. This will improve the design and make the use of your site more convenient for visitors.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.