当前位置:网站首页>Message scrolling JS implementation
Message scrolling JS implementation
2022-06-13 04:23:00 【Twinkle, twinkle, twinkle, twinkle, twinkle, twinkle, twinkle, 】
If it is the selected element , perform $(content).appendTo(selector) Is to move to selector Back , At this time $(content) The previous position will be moved to selector Back , Will change the original position
If it is a new element such as $("<li>1</li>").appendto(selector) Is added to selector Back , Will not change the original position
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Scrolling information </title>
<style>
*{
margin: 0;
padding:0;
}
.scroll-box{
width: 400px;
height: 200px;
border: 2px solid #000;
margin: 20px auto;
overflow: hidden;
}
.scroll-box ul{
list-style: none;
width: 100%;
height: 100%;
}
.scroll-box ul li{
width: 100%;
height: 40px;
box-sizing: border-box;
line-height: 40px;
text-align: center;
}
</style>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(function () {
// Get the current <ul>
var $uList = $(".scroll-box ul");
var timer = null;
// Touch the clear timer
$uList.hover(function () {
clearInterval(timer);
},function () {// Leave the start timer
timer = setInterval(function () {
scrollList($uList);
},1000);
}).trigger("mouseleave"); // Automatically trigger touch events
// Scroll animation
function scrollList(obj) {
// Get the current <li> Height
var scrollHeight = $("ul li:first").height();
// Roll out a <li> Height
$uList.stop().animate({marginTop:-scrollHeight},600,function () {
// After the animation , Will the current <ul>marginTop Set to initial value 0 state , And the first <li> Splice to the end .
$uList.css({marginTop:0}).find("li:first").appendTo($uList);
});
}
});
</script>
</head>
<body>
<div class="scroll-box">
<ul>
<li>1 The good news ! The good news ! All our products are free 1</li>
<li>2 The good news ! The good news ! All our products are free 2</li>
<li>3 The good news ! The good news ! All our products are free 3</li>
<li>4 The good news ! The good news ! All our products are free 4</li>
<li>5 The good news ! The good news ! All our products are free 5</li>
<li>6 The good news ! The good news ! All our products are free 6</li>
<li>7 The good news ! The good news ! All our products are free 7</li>
<li>8 The good news ! The good news ! All our products are free 8</li>
</ul>
</div>
</body>
</html>
边栏推荐
- Get parameters on link
- Dumi builds a document blog
- Consolidated figures
- Lenovo notebook computer uses the insert key. When the mouse becomes a small square, how to solve it
- SCM: introduction and operation of EEPROM
- Unity shader learning 004 shader debugging platform difference third-party debugging tools
- [test development] installation of test management tool Zen path
- UE4 learning notes - functions of terrain tool
- 1.4.2 Capital Market Theroy
- Single chip microcomputer: d/a output
猜你喜欢
SCM: introduction to Modbus communication protocol
高等数学(第七版)同济大学 习题1-3 个人解答
Use the visual studio code terminal to execute the command, and the prompt "because running scripts is prohibited on this system" will give an error
R: Airline customer value analysis practice
MCU: NEC protocol infrared remote controller
The most detailed swing transformer mask of window attachment in history -- Shaoshuai
How to use debounce in lodash to realize anti shake
Differences and relations between three-tier architecture and MVC
February 25, 2021 (Archaeology 12 year Landbridge provincial competition)
剑指 Offer 56 - I. 数组中数字出现的次数
随机推荐
dumi 搭建文檔型博客
电磁兼容常用名词术语
MySQL index
Hugo blog building tutorial
Uni app dynamic add style dynamic bind background image invalid
【LeetCode】860. Change with lemonade (2 brushes for wrong questions)
一款开源的Markdown转富文本编辑器的实现原理剖析
Configuration and practice of shardingsphere JDBC sub database separation of read and write
CTFSHOW SQL注入篇(231-253)
How to use debounce in lodash to realize anti shake
Redis
Use ASE encryption and decryption cache encapsulation in Vue project
Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
Single chip microcomputer: d/a output
【剑指Offer】面试题24.反转链表
SCM: introduction to Modbus communication protocol
120. 三角形最小路径和-动态规划
Zoom and move the H5 part of the mobile end
Modeling discussion series 143 data processing, analysis and decision system development
Single chip microcomputer: basic concepts of a/d and d/a