<!doctype html>
<html lang="en">
<head id="head">
<meta charset="UTF-8" />
<title>Document</title>
<script src="jquery-3.1.1.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="marquee.css" />
<style type="text/css" id="style"></style>
</head>
<body>
<div>
![](logo.gif)
<div id="cabinet">
<p id="marquee">
<font style="color: #F00;"><b>中共中央政治局4月25日召开会议,分析研究当前经济形势和经济工作,审议《关于巡视中央政法单位情况的专题报告》。阿斯顿</b></font><font style="color: #fff;"><b>阿斯顿</b></font>
</p>
</div>
</div>
</body>
<script type="text/javascript">
window.onresize = function() {
location = location
};
// 创建对象
var img = new Image();
var width, height, width_p;
// 改变图片的src
img.src = "logo.gif";
// 判断是否有缓存
if (img.complete) {
width = document.body.clientWidth - $('img').width();
height = $('#img').height();
width_p = $('p').width();
doSomething();
} else {
// 加载完成执行
img.onload = function() {
width = document.body.clientWidth - $('img').width();
height = $('#img').height();
width_p = $('p').width();
doSomething();
};
console.log(width+"--"+height);
}
function doSomething(){
$('#cabinet').width(width);
$('#cabinet').height(height);
$('#cabinet').css('line-height', height + "px");
$("#marquee").height(height);
var dom = document.getElementById('style');
dom.innerHTML = '#marquee{animation: intro 30s infinite linear;} @keyframes intro { from{margin-left:100%;} to {margin-left: ' + -width_p + 'px;}}' //向id为style的style标签添加css3动画
}
</script>
</html>
网友评论