Home Web Front-end JS Tutorial Code example for JS to complete information scrolling function

Code example for JS to complete information scrolling function

May 20, 2017 pm 01:15 PM

This article mainly introduces Javascript to achieve information scrolling effect in detail. It has certain reference value. Interested friends can refer to it.

The example of this article shares with you the js information scrolling effect. The specific code is for your reference. The specific content is as follows

Seamless scrolling upward:

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

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

<html>

<head>

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

<title>向上无缝滚动</title>

<style>

body {

 font-size: 12px;

 line-height: 24px;

 text-algin: center;  /* 页面内容居中 */

}

* {

 margin: 0px;

 padding: 0px;   /* 去掉所有标签的marign和padding的值 */

}

ul {

 list-style: none;   /* 去掉ul标签默认的点样式 */

}

a img {

 border: none;  /* 超链接下,图片的边框 */

}

a {

 color: #333;

 text-decoration: none;  /* 超链接样式 */

}

a:hover {

 color: #ff0000;

}

#mooc {

 width: 399px;

 border: 5px solid #ababab;

 -moz-border-radius: 15px;  /* Gecko browsers */

 -webkit-border-radius: 15px; /* Webkit browsers */

 border-radius: 15px;

 box-shadow: 2px 2px 10px #ababab;

 margin: 50px auto 0;

 text-align: left;    /* 让新闻内容靠左 */

}

/* 头部样式 */

#moocTitle {

 height: 62px;

 overflow: hidden; /* 这个一定要加上,内容超出的部分要隐藏,免得撑高头部 */

 font-size: 26px;

 line-height: 62px;

 padding-left: 30px;

 background-image: -moz-linear-gradient(top, #f05e6f, #c9394a); /* Firefox */

 background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f05e6f), color-stop(1, #c9394a)); /* Saf4+, Chrome */

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#8fa1ff&#39;, endColorstr=&#39;#f05e6f&#39;, GradientType=&#39;0&#39;); /* IE*/

 border: 1px solid ##f05e6f;

 -moz-border-radius: 8px 8px 0 0;  /* Gecko browsers */

 -webkit-border-radius: 8px 8px 0 0; /* Webkit browsers */

 border-radius: 8px 8px 0 0;

 color: #fff;

 position: relative;

}

#moocTitle a {

 position: absolute;

 right: 10px;

 bottom: 10px;

 display: inline;

 color: #fff;

 font-size: 12px;

 line-height: 24px;

}

/* 底部样式 */

#moocBot {

 width: 399px;

 height: 10px;

 overflow: hidden;  /* 这个一定要加上,内容超出的部分要隐藏,免得撑高底部结构 */

}

/* 中间样式 */

#moocBox {

 height: 144px;

 width: 335px;

 margin-left: 25px;

 margin-top: 10px;

 overflow: hidden; /* 这个一定要加,超出的内容部分要隐藏,免得撑高中间部分 */

}

#mooc ul li {

 height: 24px;

}

#mooc ul li a {

 width: 180px;

 float: left;

 display: block;

 overflow: hidden;

 text-indent: 15px;

 height: 24px;

}

#mooc ul li span {

 float: right;

 color: #999;

}

</style>

</head>

 

<body>

<!-- 慕课网课程公告开始 -->

<p id="mooc">

<!-- 头部 -->

<h3 id="moocTitle">最新课程<a href="#" target="_self">更多>></a> </h3>

<!-- 头部结束 -->

<!-- 中间 -->

<p id="moocBox">

 <ul id="con1">

  <li><a href="#">1.学会html5 绝对的屌丝逆袭(案例)</a><span>2013-09-18</span></li>

  <li><a href="#">2.tab页面切换效果(案例)</a><span>2013-10-09</span></li>

  <li><a href="#">3.圆角水晶按钮制作(案例)</a><span>2013-10-21</span></li>

  <li><a href="#">4.HTML+CSS基础课程(系列)</a><span>2013-11-01</span></li>

  <li><a href="#">5.分页页码制作(案例)</a><span>2013-11-06</span></li>

  <li><a href="#">6.导航条菜单的制作(案例)</a><span>2013-11-08</span></li>

  <li><a href="#">7.信息列表制作(案例)</a><span>2013-11-15</span></li>

  <li><a href="#">8.下拉菜单制作(案例)</a><span>2013-11-22</span></li>

  <li><a href="#">9.如何实现“新手引导”效果</a><span>2013-12-06</span></li>

 </ul>

 <ul id="con2">

 </ul>

</p>

<!-- 中间结束 -->

</p>

<!-- 慕课网课程公告结束 -->

 

<script type="text/javascript">

 var area = document.getElementById(&#39;moocBox&#39;);

 var con1 = document.getElementById(&#39;con1&#39;);

 var con2 = document.getElementById(&#39;con2&#39;);

 var speed = 50;

 area.scrollTop = 0;

 con2.innerHTML = con1.innerHTML;

 function scrollUp(){

  if(area.scrollTop >= con1.scrollHeight) {

   area.scrollTop = 0;

   }else{

   area.scrollTop ++;

   }

}

var myScroll = setInterval("scrollUp()",speed);

area.onmouseover = function(){

  clearInterval(myScroll);

 }

area.onmouseout = function(){

  myScroll = setInterval("scrollUp()",speed);

 }

 </script>

</body>

</html>

Copy after login

Intermittent scrolling:

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

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

<html>

<head>

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

<title>新闻无缝向上无缝滚动</title>

<style>

body {

 font-size: 12px;

 line-height: 24px;

 text-algin: center;  /* 页面内容居中 */

}

* {

 margin: 0px;

 padding: 0px;   /* 去掉所有标签的marign和padding的值 */

}

ul {

 list-style: none;   /* 去掉ul标签默认的点样式 */

}

a img {

 border: none;  /* 超链接下,图片的边框 */

}

a {

 color: #333;

 text-decoration: none;  /* 超链接样式 */

}

a:hover {

 color: #ff0000;

}

#mooc {

 width: 399px;

 border: 5px solid #ababab;

 -moz-border-radius: 15px;  /* Gecko browsers */

 -webkit-border-radius: 15px; /* Webkit browsers */

 border-radius: 15px;

 box-shadow: 2px 2px 10px #ababab;

 margin: 50px auto 0;

 text-align: left;    /* 让新闻内容靠左 */

}

/* 头部样式 */

#moocTitle {

 height: 62px;

 overflow: hidden; /* 这个一定要加上,内容超出的部分要隐藏,免得撑高头部 */

 font-size: 26px;

 line-height: 62px;

 padding-left: 30px;

 background-image: -moz-linear-gradient(top, #f05e6f, #c9394a); /* Firefox */

 background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f05e6f), color-stop(1, #c9394a)); /* Saf4+, Chrome */

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#8fa1ff&#39;, endColorstr=&#39;#f05e6f&#39;, GradientType=&#39;0&#39;); /* IE*/

 border: 1px solid ##f05e6f;

 -moz-border-radius: 8px 8px 0 0;  /* Gecko browsers */

 -webkit-border-radius: 8px 8px 0 0; /* Webkit browsers */

 border-radius: 8px 8px 0 0;

 color: #fff;

 position: relative;

}

#moocTitle a {

 position: absolute;

 right: 10px;

 bottom: 10px;

 display: inline;

 color: #fff;

 font-size: 12px;

 line-height: 24px;

}

/* 底部样式 */

#moocBot {

 width: 399px;

 height: 10px;

 overflow: hidden;  /* 这个一定要加上,内容超出的部分要隐藏,免得撑高底部结构 */

}

/* 中间样式 */

#moocBox {

 height: 144px;

 width: 335px;

 margin-left: 25px;

 margin-top: 10px;

 overflow: hidden; /* 这个一定要加,超出的内容部分要隐藏,免得撑高中间部分 */

}

#mooc ul li {

 height: 24px;

}

#mooc ul li a {

 width: 180px;

 float: left;

 display: block;

 overflow: hidden;

 text-indent: 15px;

 height: 24px;

}

#mooc ul li span {

 float: right;

 color: #999;

}

</style>

</head>

 

<body>

<!-- 慕课网课程公告开始 -->

<p id="mooc">

<!-- 头部 -->

<p id="moocTitle">慕课网最新课程<a href="#" target="_self">更多>></a> </p>

<!-- 头部结束 -->

<!-- 中间 -->

<p id="moocBox">

 <ul>

  <li><a href="#">1.学会html5 绝对的屌丝逆袭(案例)</a><span>2013-09-18</span></li>

  <li><a href="#">2.tab页面切换效果(案例)</a><span>2013-10-09</span></li>

  <li><a href="#">3.圆角水晶按钮制作(案例)</a><span>2013-10-21</span></li>

  <li><a href="#">4.HTML+CSS基础课程(系列)</a><span>2013-11-01</span></li>

  <li><a href="#">5.分页页码制作(案例)</a><span>2013-11-06</span></li>

  <li><a href="#">6.导航条菜单的制作(案例)</a><span>2013-11-08</span></li>

  <li><a href="#">7.信息列表制作(案例)</a><span>2013-11-15</span></li>

  <li><a href="#">8.下拉菜单制作(案例)</a><span>2013-11-22</span></li>

  <li><a href="#">9.如何实现“新手引导”效果</a><span>2013-12-06</span></li>

 </ul>

</p>

<!-- 中间结束 -->

<!-- 底部 -->

<p id ="moocBot"> </p>

<!-- 底部结束 -->

</p>

<!-- 慕课网课程公告结束 -->

 

<script type="text/javascript">

 var area = document.getElementById(&#39;moocBox&#39;);

 var iliHeight = 24;//单行滚动的高度

 var speed = 50;//滚动的速度

 var time;

 var delay= 2000;

 area.scrollTop=0;

 area.innerHTML+=area.innerHTML;//克隆一份一样的内容

 function startScroll(){

  time=setInterval("scrollUp()",speed);

  area.scrollTop++;

  }

 function scrollUp(){

  if(area.scrollTop % iliHeight==0){

   clearInterval(time);

   setTimeout(startScroll,delay);

   }else{

    area.scrollTop++;

    if(area.scrollTop >= area.scrollHeight/2){

     area.scrollTop =0;

     }

    }

  }

  setTimeout(startScroll,delay)

 </script>

</body>

</html>

Copy after login

[Related Recommended】

1. Free Javascript video tutorial

2. Detailed explanation of the method of recursively deleting elements in an array in JS

3. Detailed explanation of examples of JS completing the star rating function

4. How does JS determine whether text is full-width or half-width

5. nodejs+websocket completes a chat system function

The above is the detailed content of Code example for JS to complete information scrolling function. 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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles