search
HomeWeb Front-endJS TutorialA scrolling effect for messages with a non-fixed height from Tencent_javascript skills


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

Look at the key js code: The code is as follows:


var $ = function (d){
typeof d == "string" &&(d = document.getElementById(d));
return $.fn.call(d);
};
$.fn = function (){
this.addEvent = function (sEventType,fnHandler){
if (this.addEventListener) {this.addEventListener(sEventType, fnHandler, false);}
else if (this.attachEvent) {this.attachEvent("on " sEventType, fnHandler);}
else {this["on" sEventType] = fnHandler;}
}
this.removeEvent = function (sEventType,fnHandler){
if (this.removeEventListener) {this.removeEventListener(sEventType, fnHandler, false);}
else if (this.detachEvent) {this.detachEvent("on" sEventType, fnHandler);}
else { this["on" sEventType] = null;}
}
return this;
};
var Class = {create: function() {return function() { this.initialize.apply(this, arguments); }}} ;
var Bind = function (obj,fun,arr){return function() {return fun.apply(obj,arr);}}
var Marquee = Class.create();
Marquee. prototype = {
initialize: function(id,name,out,speed) {
this.name = name;
this.box = $(id);
this.out = 3;/ /Scroll interval time, unit second
this.speed = speed;
this.d = 1;
this.box.style.position = "relative";
this.box.scrollTop = 0 ;
var _li = this.box.firstChild;
while(typeof(_li.tagName)=="undefined")_li = _li.nextSibling;
this.lis = this.box.getElementsByTagName(_li .tagName);
this.len = this.lis.length;
for(var i=0;ivar __li = document.createElement(_li. tagName);
__li.innerHTML = this.lis[i].innerHTML;
this.box.appendChild(__li);//cloneNode
if(this.lis[i].offsetTop>=this .box.offsetHeight)break;
}
this.Start();
this.box.addEvent("mouseover",Bind(this,function(){clearTimeout(this.timeout);}, []));
this.box.addEvent("mouseout",Bind(this,this.Start,[]));
},
Start:function (){
clearTimeout( this.timeout);
this.timeout = setTimeout(this.name ".Up()",this.out*1000)
},
Up:function(){
clearInterval(this .interval);
this.interval = setInterval(this.name ".Fun()",10);
},
Fun:function (){
this.box.scrollTop =this .speed;
if(this.lis[this.d].offsetTop clearInterval(this.interval);
this.box.scrollTop = this.lis [this.d].offsetTop;
this.Start();
this.d ;
}
if(this.d >= this.len 1){
this. d = 1;
this.box.scrollTop = 0;
}
}
};
$(window).addEvent("load",function (){
marquee = new Marquee("msg_weibo","marquee",1,2);
});


The implementation idea is the same as the previous text scrolling, which is to fill the current container first. Then scroll up through scrollTop, but the distance of each scroll is not fixed, it is the height of the current scroll message. Due to the difference between scrollTop (the height of scrolling out of the current visible area) and offsetTop (the distance from the top of the parent node, often used to obtain the coordinate position of an element on the page), through if(this.lis[this.d].offsetTop
I think the highlight is the way $ is written. Usually obj||document.getElementById('objId') is removed from Prototype. In addition, he also binds some methods to obj. Is its role similar to the prototype's method of extending String, Array and other objects? This can be learned from.
In addition, when filling the container during initialization, use document.createElement->assign innerHTML->appendChild to do it. I think it is not as good as directly cloneNode(true)->appendChild. If it is wrong, please correct me.
The main thing is to fill in the gaps this month, haha.
Statement
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
消息已发出但被对方拒收是什么意思消息已发出但被对方拒收是什么意思Mar 07, 2024 pm 03:59 PM

消息已发出但被对方拒收是所发送的信息已经成功地从设备发送出去,但由于某种原因,对方并没有接收到这条信息。更具体地说,这通常是因为对方已经设置了某些权限或采取了某些操作,导致你的信息无法被正常接收。

如何在iOS 17上的iMessage中向右滑动并快速回复如何在iOS 17上的iMessage中向右滑动并快速回复Sep 20, 2023 am 10:45 AM

如何在iPhone上使用滑动在iMessages中回复注意:滑动回复功能仅适用于iOS17中的iMessage对话,不适用于“信息”应用程序中的常规SMS对话。在iPhone上打开“消息”应用。然后,前往iMessage对话,只需在您要回复的iMessage上向右滑动即可。完成此操作后,所选的iMessage将成为焦点,而所有其他消息将在背景中模糊不清。您将看到一个文本框,用于键入回复以及“+”图标,用于访问iMessage应用程序,如“签到”、“位置”、“贴纸”、“照片”等。只需输入您的消息,

iOS 17:如何在消息中使用表情符号作为贴纸iOS 17:如何在消息中使用表情符号作为贴纸Sep 18, 2023 pm 05:13 PM

在iOS17中,Apple在其消息应用程序中添加了几项新功能,以使与其他Apple用户的交流更具创意和乐趣。其中一个功能是能够使用表情符号作为贴纸。贴纸已经在消息应用程序中存在多年了,但到目前为止,它们并没有太大变化。这是因为在iOS17中,Apple将所有标准表情符号视为贴纸,允许它们以与实际贴纸相同的方式使用。这本质上意味着您不再局限于在对话中插入它们。现在,您还可以将它们拖到消息气泡上的任何位置。您甚至可以将它们堆叠在一起,以创建小表情符号场景。以下步骤向您展示了它在iOS17中的工作方式

如何在iPhone上编辑消息如何在iPhone上编辑消息Dec 18, 2023 pm 02:13 PM

iPhone上的原生“信息”应用可让您轻松编辑已发送的文本。这样,您可以纠正您的错误、标点符号,甚至是自动更正可能已应用于您的文本的错误短语/单词。在这篇文章中,我们将了解如何在iPhone上编辑消息。如何在iPhone上编辑消息必需:运行iOS16或更高版本的iPhone。您只能在“消息”应用程序上编辑iMessage文本,并且只能在发送原始文本后的15分钟内编辑。不支持非iMessage信息文本,因此无法检索或编辑它们。在iPhone上启动消息应用程序。在“信息”中,选择要从中编辑消息的对话

消息已发出但被对方拒收了是拉黑还是删除消息已发出但被对方拒收了是拉黑还是删除Mar 12, 2024 pm 02:41 PM

1、被加入黑名单:消息已发出但被对方拒收了一般是被拉黑了,这时你将无法向对方发送消息,对方也无法收到你的消息。2、网络问题:如果接收方的网络状况不佳,或者存在网络故障,就可能导致消息无法成功接收。此时,可以尝试等待网络恢复正常后再次发送消息。3、对方设置了免打扰:如果接收方在微信中设置了免打扰功能,那么在一定时间内,发送方的消息将不会被提醒或显示。

Vivox100s发布日期确定!最新消息抢先知Vivox100s发布日期确定!最新消息抢先知Mar 22, 2024 pm 02:18 PM

Vivox100s发布日期确定!最新消息抢先知近日,科技界掀起了一股关于Vivox100s的热潮,这款备受期待的产品终于确定了发布日期,让众多消费者和科技爱好者为之兴奋不已。据悉,Vivox100s将在本月底正式发布,届时将带来哪些惊喜,备受关注的新品到底有何亮点,让我们一同揭开这个科技谜团。Vivox100s作为Vivox系列的最新力作,自曝光以来就备受关

小米14Pro怎么设置来消息亮屏?小米14Pro怎么设置来消息亮屏?Mar 18, 2024 pm 12:07 PM

小米14Pro是一款性能配置非常出色的旗舰机型,自从正式发布以来就拥有很高的销量,小米14Pro的很多小功能是会被大家忽视的,比如说是设置来消息亮屏,功能虽小,但是是十分实用的,在使用手机的过程中大家会遇到各种问题,那么小米14Pro怎么设置来消息亮屏呢?小米14Pro怎么设置来消息亮屏?步骤一:打开手机的“设置”应用。步骤二:向下滑动直到找到“锁定屏幕和密码”选项,并点击进入。步骤三:在“锁定屏幕和密码”菜单中,找到并点击“接收通知时亮屏”选项。步骤四:在“接收通知时亮屏”页面中,打开开关以启

如何使用 FaceTime 留言 iPhone 视频消息如何使用 FaceTime 留言 iPhone 视频消息Oct 26, 2023 pm 11:25 PM

随着iOS17的发布,Apple为其移动操作系统添加了丰富的新功能,特性和增强功能。其中之一是如果有人错过您的电话,现在可以离开FaceTimeiPhone视频消息和音频。留言后,您的朋友和家人甚至可以在他们的AppleWatch上播放您的信息,让您更方便地保持联系。在FaceTime通话中留下视频消息的第一步是发起通话。如果另一端的人没有接听电话,屏幕上会出现一个录制视频的选项。点击此选项后,倒计时从5到1开始,之后您可以开始录制消息。该界面是用户友好的,具有“再次呼叫”按钮和“录制视频”按钮

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.