美文网首页
向上运动非完整版

向上运动非完整版

作者: 明明明明如月 | 来源:发表于2018-10-21 18:44 被阅读0次

效果如图:

代码如下:speed为速度,可以自行修改,但是不可以为0.1等。否则无效

<!DOCTYPE html>

<html lang="zh">

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<meta http-equiv="X-UA-Compatible" content="ie=edge" />

<title>向上无缝滚动,可以改成左右无缝滚动</title>

<style type="text/css">

*{

margin: 0;

padding: 0;

}

#active ul li{

width: 150px;

height: 50px;

list-style: none;

  box-sizing: border-box;

/*border: 1px solid blue;*/

}

#active ul{

position: absolute;

}

a{

text-decoration: none;

font-size: 12px;

}

#active{

overflow: hidden;

background: yellow;

width: 150px;

height: 200px;

margin: 100px auto;

position: relative;

}

</style>

</head>

<body>

<button id="button1">向上运动</button>

<button  id="button2">向下运动</button>

<div>鼠标移入清除定时器,移除重新载入定时器</div>

<div id="active">

<ul>

<li><a href="javascript:;">1.你生活在光亮里,你就觉得全世界都是光亮的。</a></li>

<li><a href="javascript:;">2.你要是铁了心要走,那我也铁了</a></li>

<li><a href="javascript:;">3.无问西东,只问自由,只问盛放,只问深情</a></li>

<li><a href="javascript:;">4.如果你有梦想,就要去捍卫它。 </a></li>

</ul>

</div>

</body>

</html>

<script type="text/javascript">

    var button1=document.getElementById('button1')

    var button2=document.getElementById('button2')

var oDiv=document.getElementById('active')

var oUl=oDiv.getElementsByTagName('ul')[0]

var aLi=oUl.getElementsByTagName('li')

oUl.innerHTML=oUl.innerHTML+oUl.innerHTML

oUl.style.height=aLi[0].offsetHeight*aLi.length+'px'

oUl.style.background='pink'

var speed=1;//速度

//定时器里面的函数

function move(){

if(oUl.offsetTop<=-oUl.offsetHeight/2){

oUl.style.top='0';

}

if(oUl.offsetTop>0){

oUl.style.top=-oUl.offsetHeight/2+'px'

}

oUl.style.top=oUl.offsetTop+speed+'px'

}

var timer=setInterval(move,30)

oDiv.onmouseover=function(){

clearInterval(timer)

}

oDiv.onmouseout=function(){

timer=setInterval(move,30)

}

button1.onclick=function(){

console.log('向上运动')

speed=-1

}

button2.onclick=function(){

console.log('向下运动')

speed=+1

}

</script>

相关文章

  • 向上运动非完整版

    效果如图: 代码如下:speed为速度,可以自行修改,但是不可以为0.1等。否则无效

  • vue完整版和非完整版的区别和用法

    1.vue完整版和非完整版的区别 2、Vue完整版与非完整版的一些优劣: 完整版 优点:逻辑清晰简单,好写好用。 ...

  • Vue完整版与非完整版

    本文主要介绍Vue完整版与非完整版的区别与优缺点: :总是使用非完整版,然后配合vue-loader和vue文件 ...

  • Vue 模板 template

    模板 template 一、 Vue完整版,写在HTML里 二、 Vue完整版,写在选项里 三、Vue非完整版,配...

  • 模板 template 三种写法

    一、 Vue 完整版,写在HTML里 二、Vue完整版,写在选项里 三、Vue 非完整版,配合 xxx.vue 文...

  • Vue模板、指令与修饰符

    模板template三种写法 一. Vue完整版,写在HTML中 二. Vue完整版,写在选项里 三. Vue非完...

  • Oralce 创建用户

    完整版 创建临时表空间(非必须) 创建数据表空间(非必须) TEMPFILE和DATAFILE需要根据实际情况创建...

  • Vue 完整版 VS 非完整版

    一、两个版本对应的文件名 含 min 的是压缩版,表示是在生产环境下给用户使用的版本,取消了注释和警告 完整版本文...

  • 《土耳其瞭望塔》技巧分析(三)(多图预警)

    运动匹配 镜头运动方向匹配 镜头向前推进 镜头向后拉远 镜头向左运动 镜头向右运动 镜头向上运动 镜头向下运动 镜...

  • 了解vue 完整版与非完整版

    完整版 : vue.js 支持从html获取视图。支持template。有complier编译器,而complie...

网友评论

      本文标题:向上运动非完整版

      本文链接:https://www.haomeiwen.com/subject/qwtizftx.html