The example in this article describes the method of implementing rolling news in javaScript. Share it with everyone for your reference. The details are as follows:
The rolling_new.html page is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <style type="text/css"> *{margin:0;padding:0;} #news{display:none;} </style> <body> <div id="news"> 太平天国医疗卫生组织,在国家制度上,有一定的组织,已经形成为一 种正规化的制度。它可分为朝内、军中、居民三个系统。 种正规化的制度。它可分为朝内、军中、居民三个系统。 种正规化的制度。它可分为朝内、军中、居民三个系统。 种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。种正规化的制度。它可分为朝内、军中、居民三个系统。 </div> <div id="show_news"> </div> </body> <script type="text/javascript"> function $(node){ return document.getElementById(node); } function getElementsByClassName(str,root,tag){ if(root){ root=typeof root=="string"?document.getElementById(root):root; }else{ root=document.body; } tag=tag||"*"; var els=root.getElementsByTagName(tag),arr=[]; for(var i=0,n=els.length;i<n;i++){ for(var j=0,k=els[i].className.split(" "),l=k.length;j<1;j++){ if(k[j]==str){ arr.push(els[i]); break; } } } return arr; } function attachEvent(node,eventType,handler){ node=typeof node=="string"?document.getElementById(node):node; if(document.all){ node.attachEvent("on"+eventType,handler); }else{ node.addEventListener(eventType,handler,false); } } function rolling_news(source,target,width,height,speed,direction){ this.source=$(source); this.source_content=$(source).innerHTML; this.target=$(target); this.width=width; //宽 this.height=height; //高 this.speed=speed; //滚动速度 this.direction=direction;//方向 this.tag=0; } rolling_news.prototype={ version:"1.00", author:"yangfeifei", date:"2011-10-23", initialize:function(){ var o=this; var target=o.target; var content=o.source_content; var innerDiv=document.createElement("div"); innerDiv.setAttribute("class","innerDiv"); o.source.innerHTML=""; innerDiv.innerHTML=o.source_content; target.appendChild(innerDiv); //显示区域样式 target.style.width=o.width+"px"; target.style.height=o.height+"px"; target.style.overflow="hidden"; target.getElementsByTagName('div')[0].style.width=o.width+"px"; target.getElementsByTagName('div')[0].style.height=target.getElementsByTagName('div')[0].scrollHeight>o.height?target.getElementsByTagName('div')[0].scrollHeight+"px":o.height+"px";//当文档实际高度大于容器时,高度为实际文档高度,否则为容器高度 //显示区域初始化 switch(o.direction){ case "up": target.scrollTop="0"; o.addAfterNode(); break; case "down": o.addBeforeNode(); target.scrollTop=target.scrollHeight-o.height; break; } //初始动作 o.autoplay(); attachEvent(o.target,'mouseover',function(){o.stop()}); attachEvent(o.target,'mouseout',function(){o.autoplay()}); }, up:function(){ var x=this; var divHeight=x.target.getElementsByTagName('div')[0].scrollHeight>x.height?x.target.getElementsByTagName('div')[0].scrollHeight:x.height; if((x.target.scrollHeight-x.target.scrollTop)!=x.height){ x.target.scrollTop=x.tag; }else{ x.addAfterNode(); x.target.removeChild(x.target.getElementsByTagName('div')[0]); x.tag=x.tag-divHeight; x.target.scrollTop=x.tag; } x.tag=x.tag+x.speed; }, down:function(){ var j=this; var divHeight=j.target.getElementsByTagName('div')[0].scrollHeight>j.height?j.target.getElementsByTagName('div')[0].scrollHeight:j.height; if(j.target.scrollTop==0){ j.addBeforeNode(); j.target.removeChild(j.target.getElementsByTagName('div')[2]); j.tag=j.tag-divHeight; j.target.scrollTop=j.target.scrollHeight-j.height-j.tag; }else{ j.target.scrollTop=j.target.scrollHeight-j.height-j.tag; } j.tag=j.tag+j.speed; }, addAfterNode:function(){ var p=this; var newDiv=document.createElement('div'); newDiv.setAttribute("class","innerDiv"); newDiv.innerHTML=p.source_content; p.target.appendChild(newDiv); newDiv.style.width=p.width+"px"; newDiv.style.height=p.target.getElementsByTagName('div')[0].scrollHeight>p.height?p.target.getElementsByTagName('div')[0].scrollHeight+"px":p.height+"px";//当文档实际高度大于容器时,高度为实际文档高度,否则为容器高度 }, addBeforeNode:function(){ var d=this; var newDiv=document.createElement('div'); newDiv.setAttribute("class","innerDiv"); newDiv.innerHTML=d.source_content; d.target.insertBefore(newDiv,d.target.getElementsByTagName('div')[0]); newDiv.style.width=d.width+"px"; newDiv.style.height=d.target.getElementsByTagName('div')[0].scrollHeight>d.height?d.target.getElementsByTagName('div')[0].scrollHeight+"px":d.height+"px";//当文档实际高度大于容器时,高度为实际文档高度,否则为容器高度 }, play:function(){ var t=this; switch(t.direction){ //向上 case "up": t.up(); break; //向右 case "down": t.down(); break; } }, autoplay:function(){ var s=this; s.auto=setInterval(function(){s.play()},1); }, stop:function(){ var h=this; clearInterval(h.auto); } } var a=new rolling_news("news","show_news",200,200,1,"down"); a.initialize(); </script> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
