我可能会与开始DIV风格为position:fixed
与display:none
:
<div id="randomp" style="display:none;position:fixed;width:165px;height:29px;background:url(/logo2.png) no-repeat;background-size: 165px;"></div>
然后使用jQuery来确定位置CSS设置并打开知名度
$(document).ready(function() {
// get jQuery object for the div
var $randomp = $('#randomp');
// determine whether to show top or bottom, left or right
var top = Math.round(Math.random()); // generate 0 or 1 value
if (top === 1) {
$randomp.css('top', '3px');
} else {
$randomp.css('bottom', '3px');
}
var left = Math.round(Math.random());
if (left === 1) {
$randomp.css('left', '3px');
} else {
$randomp.css('right', '3px');
}
// show the div
$randomp.show();
});
当然,你也可以使用服务器端代码来做到这一点,但既然你问了你的标签中的javascript/jquery,我建议这个解决方案。
请添加您的代码。 – Whistletoe
我不太确定这是否可行,但在概念上,有一个阵列的位置(可能是2D,所以它与XY很好地相关),当页面加载时,“top:x_pixel”等等。 –
我该怎么做?即时通讯如此困惑:S – Xcite