原生js弹幕效果
- 思路
- 获取弹幕value,生成弹幕后要清除input里面的value,为下一次生成弹幕做准备
- 两个时间 keydown click
- 触发后生成弹幕span,添加到父盒子中appendChild()
- 初始化span的top和left
- 使用setInterval(,1000/60)来让弹幕移动
- 当span移除屏幕时,让其消失,即offsetLeft+offsetWidth<=0时,this.parentNode.removeChild()
<style type="text/css" media="screen">
* {
margin: 0px;
padding: 0px
}
html, body {
height: 100%
}
body {
overflow: hidden;
background-color: #FFF;
text-align: center;
}
.flex-column {
display: flex;
flex-direction: column;
justify-content: space-between;align-items: center;
}
.flex-row {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.wrap {
overflow: hidden;
width: 60%;
height: 500px;
margin: 1px auto;
padding: 20px;
background-color: transparent;