隨網頁捲軸捲動移位的浮動視窗【範例一】 (javascript)

隨網頁捲軸捲動移位的浮動視窗........程式碼範例結果如右側的浮動視窗 →

程式碼:主要看紅色字部份,或直接複製所有程式碼,另存成一個 html 檔來觀看使用唄 ^^

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>喵喵笨兔 の 喵喵的家~遊戲天地 - 浮動視窗1</title>
<script>
function init() {
document.getElementById('flotLayer').style.visibility = 'visible';
MoveLayer('flotLayer');
}
function MoveLayer(layerName) {
var x = 50;
var y = 50; //浮動視窗高度位置改這裡
var _y = document.body.scrollTop + y;
var diff =(_y - parseInt(document.getElementById('flotLayer').style.top))*.40;
var rey=_y-diff;

document.getElementById('flotLayer').style.top=rey;
document.getElementById('flotLayer').style.right=x;
setTimeout("MoveLayer('flotLayer');", 50);
}
</script>
</head> <body onLoad="init()">
<!--浮動窗要靠左,把 right 改成 left 即可-->
<div id="flotLayer" style="position:absolute;width:61px;height:59px;z-index:20;visibility:hidden; right:10px;top:0px;">
<!-- 下面的寛和高是浮動視窗的大小,若改大且靠右,則也須改上面 right:??px 來調整哦-->
<div style="width:100px; height:100px; border:solid 1px #cccccc"> <p>喵喵笨兔</p>
<img src="gif/logo.gif" style="max-width:100%">
</div>
</div>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br> <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br> </body> </html>
笨兔隨手筆記於 2017/10/03

喵喵笨兔 の 喵喵的家~遊戲天地
http://vv0817.tk
http://vvv.lionfree.net
http://qo3op.asuscomm.com/vvv
https://uoedgpkhyfwzmd7zua8myg-on.drv.tw/vvv