Commit 73be78b3 by zhanghaozhe

弹幕

parent 98d6cad9
...@@ -8,24 +8,50 @@ class SystemBulletScreen extends Component { ...@@ -8,24 +8,50 @@ 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 => {
item.querySelector('span').addEventListener('transitionend', _this.transitionEnd)
})
},
slideChangeTransitionEnd() {
_this.slideHorizontal(this)
},
transitionEnd() {
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'), content = el.querySelector('span'),
contentWidth = content.offsetWidth, contentWidth = content.offsetWidth,
wrapperWidth = el.querySelector('div').clientWidth wrapperWidth = el.clientWidth
const co = 131.25 const co = 131.25
...@@ -33,56 +59,71 @@ class SystemBulletScreen extends Component { ...@@ -33,56 +59,71 @@ class SystemBulletScreen extends Component {
content.style.transition = `transform ${contentWidth / co}s linear` content.style.transition = `transform ${contentWidth / co}s linear`
setTimeout(() => { setTimeout(() => {
content.style.transform = `translate3d(${-(contentWidth - wrapperWidth) - 10}px,0,0)` content.style.transform = `translate3d(${-(contentWidth - wrapperWidth) - 10}px,0,0)`
}, 3000) }, 1000)
console.log(contentWidth, wrapperWidth)
} else { } else {
_this.swiper.slideNext() this.swiper.slideNext()
}
},
transitionEnd() {
console.log(this.slides[this.activeIndex])
} }
} }
})
}
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 &&
<div id="system-bullet-screen" onTransitionEnd={this.removeSystemNotices} ref={el => this.sysNotice = el}>
<img className='avatar'
src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/newyear20/system-avatar.png' alt=""/>
<div className='sys-bullet-screen-swiper-container'>
<ul className="swiper-wrapper"> <ul className="swiper-wrapper">
{ {
bullets && bullets.length && bullets.map((item, index) => { bullets && bullets.length && bullets.map((item, index) => {
return ( return (
<li className="swiper-slide" key={index}> <li className="swiper-slide" key={index}>
<img className='avatar' <span>{item}</span>
src='https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/newyear20/system-avatar.png' alt=""/>
<div><span onTransitionEnd={this.transitionEnd}>{item}</span></div>
</li> </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;
overflow: hidden; align-items: center;
div{ transition: height .3s ease-in-out;
width: 100%;
overflow: hidden; .sys-bullet-screen-swiper-container{
height: 100%;
} }
span{
ul {
flex: auto;
max-width: 293px;
}
li {
overflow: hidden;
height: 30px;
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