HTML
html
<div class="marquee">
<img src="./img/laba.png" alt="" />
<div class="marquee-container">
<div class="marquee-content"></div>
</div>
</div>
CSS
css
.print {
width: 100%;
height: 400px;
background-image: url('../img/xiehui.png');
background-size: 100% 100%;
}
.marquee {
width: 96%;
height: 60px;
margin-left: 2%;
background-color: #fcfdfe;
margin-top: -30px;
border-radius: 10px;
}
.marquee img {
width: 10%;
margin-top: 10px;
float: left;
}
.marquee-container {
width: 87%;
height: 30px;
line-height: 30px;
float: left;
margin-top: 15px;
margin-left: 2%;
overflow: hidden;
position: relative;
text-wrap: nowrap;
box-sizing: border-box;
}
.marquee-content {
display: inline-block;
position: absolute;
text-wrap: nowrap;
}
JS
javascript
function marquee(data) {
console.log(data.data.announ[0].content);
$('.marquee-content').html(data.data.announ[0].content);
const container = document.querySelector('.marquee-container');
const content = document.querySelector('.marquee-content');
const containerWidth = container.offsetWidth;
console.log(containerWidth);
const contentWidth = content.scrollWidth;
let startPosition = containerWidth;
content.style.left = `${startPosition}px`;
function animateMarquee() {
startPosition--;
if (startPosition < -contentWidth) {
startPosition = containerWidth;
}
content.style.left = `${startPosition}px`;
requestAnimationFrame(animateMarquee);
}
animateMarquee();
}
时间慢点 看的更清晰哈哈哈!