我可能會與開始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