为了账号安全,请及时绑定邮箱和手机立即绑定

下面有一段关于javascript的代码,其中写有this.element句子是什么意思?

下面有一段关于javascript的代码,其中写有this.element句子是什么意思?

DIEA 2021-05-26 18:15:47
下面代码中this.element.scrollTop 是什么意思<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">#divMsg{line-height:20px;height:20px;overflow:hidden;}</style><script type="text/javascript">var Scroll = new function(){this.delay = 2000; //延迟的时间this.height = 20; //行的高度this.step = 4; //步长this.curHeight= 0;this.stimer = null;this.timer = null;this.start = function(){ //开始翻页-调用move方法this.move();}this.move = function(){var self = this;if(this.curHeight == this.height) //如果显示完一行{this.timer = setTimeout(function() { //使用定时器-定时下一行的翻页时间self.move();}, this.delay);this.curHeight = 0;if(this.element.scrollTop >= this.element.scrollHeight - this.height){ //滚动信息已经完毕,就是这里this.element.scrollTop 是什么意思this.element.scrollTop = 0;}return true;}this.element.scrollTop += this.step;this.curHeight += this.step;this.timer = setTimeout(function(){ //设置自动翻页定时器self.move();}, 30);}this.stop = function(){ //清除定时期,停止滚动翻页clearTimeout(this.timer);}}</script></head><body><div id="divMsg">张三奥运会历史性的突破,拿到了男子100米金牌<br/>奥运会历史上的首位8金得主<br/>北京奥运会欢迎志愿者的参与<br/>奥运会带来了什么样的商机<br/>北京奥运会2008年举行<br/>娱乐新闻请转到娱乐主页<br/>今天又获得一枚金牌<br/></div><script type="text/javascript">Scroll.element = document.getElementById('divMsg');Scroll.start();</script><input type="button" value="开始" onclick="Scroll.start()"/><input type="button" value="停止" onclick="Scroll.stop()"/></body></html>
查看完整描述

2 回答

?
米脂

TA贡献1836条经验 获得超3个赞

var Scroll = new function(){
this.delay = 2000; //延迟的时间
this.height = 20; //行的高度
this.step = 4; //步长
this.curHeight= 0;
this.stimer = null;
this.timer = null;
this.start = function(){ //开始翻页-调用move方法
this.move();
}
这段代码可以理解为 创建了一个Scroll 类 而 this 是这个类的指针,可以调用这里类中的所有元素,方法,属性等

this.element.scrollTop 是获取当前<div id="divMsg"> div的位置
Scroll.element = document.getElementById('divMsg'); 这句就是把 名为 divMsg 的 DIV 的对象 赋值给Scroll这个类



查看完整回答
反对 回复 2021-05-31
  • 2 回答
  • 0 关注
  • 320 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信