Home Web Front-end JS Tutorial Simple jQuery banner image carousel example code_jquery

Simple jQuery banner image carousel example code_jquery

May 16, 2016 pm 03:12 PM

A friend showed me a carousel effect. I downloaded the js and took a look. Such a simple effect of Yaya can be written in hundreds of lines. It seriously affects the loading speed of the browser. I thought that people have broadband Traffic is free to play. . In desperation, I wrote a simple one for him. All the codes did not exceed 70 lines, and there was also the CSS with rounded corners. Not every browser has rounded corners, but it does not affect the appearance, hehe.

Let me show you the renderings first:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>无标题页</title>

<script src="js/jquery-2.1.4.js" type="text/javascript"></script>

<style type="text/css">

.clear{overflow:hidden; clear:both; width:0px; height:0px; }

.imgbox{width:640px; margin:0 auto; text-align:center; }

ul{padding:0px; margin:0px;}

ul li{float:left; list-style:none; }

ul li.select{display:block;}

.imgnum span{border-radius:10px; font:normal normal bold 12px/15px 微软雅黑; color:#FFF; margin-left:5px; padding:3px 6px 3px 6px; background-color:#F90; cursor:pointer;}

.imgnum span.onselect{background-color:#F00;}

.imgnum{text-align:center; float:right; margin:-30px 30px; position:relative;}

</style>

</head>

<body>

<div class="imgbox">

<ul id="banner_img">

<li><img src="images/banner1.jpg"/></li>

<li><img src="images/banner2.jpg"/></li>

<li><img src="images/banner3.jpg"/></li>

<li><img src="images/banner4.jpg"/></li>

<li><img src="images/banner5.jpg"/></li>

</ul>

<div class="clear"></div>

<div class="imgnum">

<span class="onselect">1</span>

<span>2</span>

<span>3</span>

<span>4</span>

<span>5</span>

</div>

</div>

<script type="text/javascript">

var time = "";

var index = 1;

$(function () {

showimg(index);

//鼠标移入移出

$(".imgnum span").hover(function () {

clearTimeout(time);

var icon=$(this).text();

$(".imgnum span").removeClass("onselect").eq(icon-1).addClass("onselect");

$("#banner_img li").hide().stop(true,true).eq(icon-1).fadeIn("slow");

}, function () {

index=$(this).text()> 4 ? 1 :parseInt($(this).text())+1;

time = setTimeout("showimg(" + index + ")", 3000);

});

});

function showimg(num) {

index = num;

$(".imgnum span").removeClass("onselect").eq(index-1).addClass("onselect");

$("#banner_img li").hide().stop(true,true).eq(index-1).fadeIn("slow");

index = index + 1 > 5 ? 1 : index + 1;

time = setTimeout("showimg(" + index + ")", 3000);

}

</script>

</body>

</html>

Copy after login

Be sure to quote the Jquery file. I won’t upload the image. You can replace it yourself. Pay attention to the length and width of the image.

The above is a simple jQuery banner image carousel example code shared by the editor. I hope it will be helpful to everyone!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

Example Colors JSON File Example Colors JSON File Mar 03, 2025 am 12:35 AM

Example Colors JSON File

10 jQuery Syntax Highlighters 10 jQuery Syntax Highlighters Mar 02, 2025 am 12:32 AM

10 jQuery Syntax Highlighters

8 Stunning jQuery Page Layout Plugins 8 Stunning jQuery Page Layout Plugins Mar 06, 2025 am 12:48 AM

8 Stunning jQuery Page Layout Plugins

Build Your Own AJAX Web Applications Build Your Own AJAX Web Applications Mar 09, 2025 am 12:11 AM

Build Your Own AJAX Web Applications

What is 'this' in JavaScript? What is 'this' in JavaScript? Mar 04, 2025 am 01:15 AM

What is 'this' in JavaScript?

10  JavaScript & jQuery MVC Tutorials 10 JavaScript & jQuery MVC Tutorials Mar 02, 2025 am 01:16 AM

10 JavaScript & jQuery MVC Tutorials

See all articles