|
|

楼主 |
发表于 2022-3-23 18:38
|
显示全部楼层
239楼:JS动态生成CSS @keyframes 动画代码——
<style type="text/css">
.wai-zzmd { /* 走马灯父框 */
position: absolute;
width: 400px;
height: 30px;
overflow: hidden;
}
.wai-zzmd div {/* 走马灯文本框 */
position: absolute;
left: 400px;/*与父框宽度同 */
word-break: keep-all;
white-space: nowrap;
font: normal 20px / 30px Sans-Serif;
color: #000;
text-shadow: 1px 1px 2px rgba(0, 0, 0, .5);
}
</style>
<div class="wai-zzmd">
<div id="text-zmd">
I can fly now.
</div>
</div>
<script language="javascript">
zzmd(); //运行动画
function zzmd(){
var ziBox = document.getElementById('text-zmd');
var w = ziBox.clientWidth;
var style = document.createElement('style');
var keyframes = '@keyframes fly {to { left: -' + w + 'px;}}';
style.type = 'text/css';
style.innerHTML = keyframes;
ziBox.appendChild(style);
ziBox.style.animation = 'fly 20s linear infinite'; // 20s 根据需要修改
}
</script>
|
|