Home Web Front-end JS Tutorial Detailed analysis of JS implementation of label scrolling switching effect

Detailed analysis of JS implementation of label scrolling switching effect

Dec 25, 2017 pm 03:08 PM
javascript Label scroll

This article mainly brings you the effect of using JS to achieve scrolling switching after clicking on the item label. Friends who are interested can test it and learn it. Hope it helps everyone.

The JS effect of this article is to achieve the effect of switching the content below with the scroll when the mouse clicks on the ITEM label. Let's first take a look at the rendering after running.

The following is the running code:


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

60

61

62

63

64

65

66

67

68

69

70

71

72

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>jQuery实现的平滑滚动选项卡</title>

<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<style>

.tabs{width: 1200px; margin: 0 auto; height: 336px; overflow: hidden;}

.tabs_item{height: 36px;}

.tabs_block{height: 300px;}

.list_item{float: left; width: 200px; height: 36px; line-height: 36px; font-size: 26px; text-align: center;background-color:#FC0;cursor: pointer;}

.list_item.active{color: #FFF;background-color:#F60}

.tabs_block{width: 20000px; position: relative;}

.list_block{display: none; float: left; width: 1200px; height: 300px; font-size: 100px; text-align: center; line-height: 300px;background-color:#F4F4F4}

.list_block.show{display: block;}

</style>

<script>jQuery.easing['easeOutCubic'] = function (x, t, b, c, d) {

 return c*((t=t/d-1)*t*t + 1) + b;

};

function Tabs(tabs,list,block,item,$){

 var tabs = $(tabs);

 var width = tabs.width();

 tabs.find(list+':first').addClass('active');

 tabs.find(item+':first').addClass('show');

 tabs.find(list).click(function(){

 var $this = $(this);

 var i = tabs.find(block).find('.show').index();

 var n = $this.index();

 $this.addClass('active').siblings('.active').removeClass('active');

 tabs.find(item).eq(n).addClass('show');

 if(n > i){

 tabs.find(block).stop().animate({'left':'-'+width+'px'},600,'easeOutCubic',function(){

  tabs.find(block).css('left','0px');

  tabs.find(item).eq(n).siblings('.show').removeClass('show');

  });

 }else{

 tabs.find(block).css('left','-'+width+'px').stop().animate({'left':0},600,'easeOutCubic',function(){

  tabs.find(item).eq(n).siblings('.show').removeClass('show');

  });

 }

 });

}

</script>

</head>

<body>

 <p class="tabs">

 <p class="tabs_item">

  <p class="list_item">list item 1</p>

  <p class="list_item">list item 2</p>

  <p class="list_item">list item 3</p>

  <p class="list_item">list item 4</p>

  <p class="list_item">list item 5</p>

  <p class="list_item">list item 6</p>

 </p>

 <p class="clear"> </p>

 <p class="tabs_block">

  <p class="list_block">list block 1</p>

  <p class="list_block">list block 2</p>

  <p class="list_block">list block 3</p>

  <p class="list_block">list block 4</p>

  <p class="list_block">list block 5</p>

  <p class="list_block">list block 6</p>

 </p>

 </p>

<script type="text/javascript">

 jQuery(document).ready(function(){

  var myTabs = new Tabs('.tabs','.list_item','.tabs_block','.list_block',jQuery);

 });

</script>

<p style="text-align:center">更多代码请访问:<a href="http://www.jb51.net" target="_blank">脚本之家</a></p>

</body>

</html>

Copy after login

In the code we quoted Baidu’s jquery


1

<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

Copy after login

Related recommendations:

Detailed explanation of native JS is to control multiple scroll bars to follow the scrolling synchronously

Detailed explanation of js to determine whether the content area is scrolled to the bottom

JavaScript implementation of table scrolling and paging tutorial

The above is the detailed content of Detailed analysis of JS implementation of label scrolling switching effect. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article

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)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

How to search for text across all tabs in Chrome and Edge How to search for text across all tabs in Chrome and Edge Feb 19, 2024 am 11:30 AM

How to search for text across all tabs in Chrome and Edge

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

Monitor iframe scrolling behavior Monitor iframe scrolling behavior Feb 18, 2024 pm 08:40 PM

Monitor iframe scrolling behavior

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to? Mar 22, 2024 am 10:28 AM

How to add tags on Douyin to attract traffic? Which tags on the platform are easiest to attract traffic to?

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

See all articles