Commit 73be78b3 by zhanghaozhe

弹幕

parent 98d6cad9
...@@ -8,81 +8,122 @@ class SystemBulletScreen extends Component { ...@@ -8,81 +8,122 @@ class SystemBulletScreen extends Component {
swiper swiper
count = 0 count = 0
sysNotice
state = {
showNotices: true
}
componentDidMount() { componentDidMount() {
this.initializeSwiper() this.initializeSwiper()
} }
componentWillUnmount() {
this.swiper && this.swiper.destroy(true, true)
}
initializeSwiper = () => { initializeSwiper = () => {
const _this = this const _this = this
console.log(document.querySelector('.sys-bullet-screen-swiper-container'))
this.swiper = new Swiper('.sys-bullet-screen-swiper-container', { this.swiper = new Swiper('.sys-bullet-screen-swiper-container', {
allowTouchMove: false, allowTouchMove: false,
direction: 'vertical', direction: 'vertical',
loop: true,
on: { on: {
init() { init() {
let el = this.slides[this.activeIndex], Array.from(this.slides).forEach(item => {
content = el.querySelector('span'), item.querySelector('span').addEventListener('transitionend', _this.transitionEnd)
contentWidth = content.offsetWidth, })
wrapperWidth = el.querySelector('div').clientWidth },
slideChangeTransitionEnd() {
const co = 131.25 _this.slideHorizontal(this)
if (contentWidth > wrapperWidth) {
content.style.transition = `transform ${contentWidth / co}s linear`
setTimeout(() => {
content.style.transform = `translate3d(${-(contentWidth - wrapperWidth) - 10}px,0,0)`
}, 3000)
console.log(contentWidth, wrapperWidth)
} else {
_this.swiper.slideNext()
}
}, },
transitionEnd() { transitionEnd() {
console.log(this.slides[this.activeIndex]) const el = this.slides[this.previousIndex].querySelector('span')
el.style.transition = 'unset'
el.style.transform = 'translate3d(0,0,0)'
} }
} }
}) })
} }
slideHorizontal = (swiper) => {
let el = swiper.slides[swiper.activeIndex],
content = el.querySelector('span'),
contentWidth = content.offsetWidth,
wrapperWidth = el.clientWidth
const co = 131.25
if (contentWidth > wrapperWidth) {
content.style.transition = `transform ${contentWidth / co}s linear`
setTimeout(() => {
content.style.transform = `translate3d(${-(contentWidth - wrapperWidth) - 10}px,0,0)`
}, 1000)
} else {
this.swiper.slideNext()
}
}
transitionEnd = () => { transitionEnd = () => {
const { const {
bullets = [ bullets = [
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第一条消息,第一条消息,第一条消息,第一条消息,第一条消息,第一条消息,',
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第二条消息,第二条消息,第二条消息,第二条消息,第二条消息,第二条消息,',
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第三条消息,第三条消息,第三条消息,第三条消息,第三条消息,第三条消息,',
] ]
} = this.props } = this.props
const len = bullets.length * 3 const len = bullets.length * 3
if (++this.count === len) {
setTimeout(() => {
this.sysNotice.style.height = `0px`
}, 2000)
} else {
setTimeout(() => {
this.swiper && this.swiper.slideNext()
}, 1000)
}
}
removeSystemNotices = e => {
e.persist()
if(e.target === this.sysNotice){
this.setState({
showNotices: false
})
}
} }
render() { render() {
const { const {
bullets = [ bullets = [
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第一条消息,第一条消息,第一条消息,第一条消息,第一条消息,第一条消息,',
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第二条消息,第二条消息,第二条消息,第二条消息,第二条消息,第二条消息,',
'通知内容,后台编辑,单条超字左滑滚动显示完整,多条上下滚动轮播', '第三条消息,第三条消息,第三条消息,第三条消息,第三条消息,第三条消息,',
] ]
} = this.props } = this.props
return ( return (
<div id='system-bullet-screen' className='sys-bullet-screen-swiper-container'> this.state.showNotices &&
<ul className="swiper-wrapper"> <div id="system-bullet-screen" onTransitionEnd={this.removeSystemNotices} ref={el => this.sysNotice = el}>
{ <img className='avatar'
bullets && bullets.length && bullets.map((item, index) => { src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/newyear20/system-avatar.png' alt=""/>
return ( <div className='sys-bullet-screen-swiper-container'>
<li className="swiper-slide" key={index}> <ul className="swiper-wrapper">
<img className='avatar' {
src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/newyear20/system-avatar.png' alt=""/> bullets && bullets.length && bullets.map((item, index) => {
<div><span onTransitionEnd={this.transitionEnd}>{item}</span></div> return (
</li> <li className="swiper-slide" key={index}>
) <span>{item}</span>
}) </li>
} )
</ul> })
}
</ul>
</div>
</div> </div>
) )
} }
} }
......
@import "../user-bullet-screen/bullet-screen"; @import "../user-bullet-screen/bullet-screen";
#system-bullet-screen{
#system-bullet-screen {
overflow: hidden; overflow: hidden;
margin-top: 11px;
margin-bottom: 16px; margin-bottom: 16px;
li{ padding-left: 2px;
display: flex; display: flex;
align-items: center;
transition: height .3s ease-in-out;
.sys-bullet-screen-swiper-container{
height: 100%;
}
ul {
flex: auto;
max-width: 293px;
}
li {
overflow: hidden; overflow: hidden;
div{ height: 30px;
width: 100%;
overflow: hidden; span {
}
span{
display: inline-block; display: inline-block;
white-space: nowrap; white-space: nowrap;
line-height: 30px;
} }
} }
@extend .bullet-screen; @extend .bullet-screen;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment