当前位置:网站首页>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>
边栏推荐
- Lightweight digital mall system based on PHP
- Idea Download
- Reread the classic: end to end object detection with transformers
- Unity Shader 学习 004-Shader 调试 平台差异性 第三方调试工具
- [automated test] what you need to know about unittest
- Et framework -22 creating serverinfo entities and events
- [test development] file compression project practice
- 2019 Blue Bridge Cup
- 重读经典:《End-to-End Object Detection with Transformers》
- 在线音频调节技术汇总
猜你喜欢

Knife4j aggregation 2.0.9 supports automatic refresh of routing documents

【自动化测试】关于unittest你需要知道的事

Single chip microcomputer: pcf8591 application program

Analysis of the implementation principle of an open source markdown to rich text editor

Use ASE encryption and decryption cache encapsulation in Vue project

Single chip microcomputer: infrared remote control communication principle

第007天:go语言字符串
![[note]vs2015 compilation of masm32 using MASM32 Library](/img/f5/b47336af248d1b485208ec3f9ca12b.png)
[note]vs2015 compilation of masm32 using MASM32 Library

VGA display based on de2-115 platform

Sword finger offer II 022 Entry node of a link in a linked list
随机推荐
基于DE2-115平台的VGA显示
XOR prefix and +map maintenance
小程序基础入门(黑马学习笔记)
Application of dagger2 learning module (II)
Analysis of the implementation principle of an open source markdown to rich text editor
[sword finger offer] interview question 25 Merge two ordered linked lists
MCU: pcf8591 hardware interface
Data analysis report
Catalan number
[sword finger offer] interview question 24 Reverse linked list
R: Airline customer value analysis practice
Promise combined with await
Get parameters on link
Koa file upload and download
Idea Download
Interpretation and implementation of proxy mode
Call C function in Lua
[test development] file compression project practice
Use ASE encryption and decryption cache encapsulation in Vue project
dumi 搭建文档型博客