Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
lt;head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style>
div{
position:absolute;
}
</style>
</head>
<body>
<div id="divimg">
<img src="http://www.jungjaehyung.com/uploadfile/2024/0808/20240808042744235.png" width="150" height="150">
</div>
<script language="javascript" type="text/javascript">
//獲取圖片div對象
var img=document.getElementById("divimg");
//設置div左上角 起始點坐標
var x=0,y=0;
//設置圖片的行進速度
var xSpeed=5,ySpeed=5;
//設置圖片的最大浮動高度和寬度
var w=document.body.clientWidth-150,h=document.body.clientHeight-150;
function floatimg(){
//比較圖片是否到達邊界
//如果到達邊界以后,我控制圖片改變方向
if(x>w||x<0) xSpeed= -xSpeed;
if(y>h||y<0) ySpeed= -ySpeed;
//如果沒有到達邊界,設置圖片的左上角坐標,
//設置坐標值 起始坐標+速度
x+=xSpeed;
y+=ySpeed;
img.style.top=y+"px";
img.style.left=x+"px";
setTimeout("floatimg()",50);
}
floatimg();
</script>
</body>
<script src="https://lf3-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
1.鼠標不斷的移動,使用鼠標移動事件:mousemove
2.在頁面中移動,給document注冊事件
3.圖片要移動距離,而且不占位置,我們使用絕對定位即可
4.核心原理:每次鼠標移動,我們都會獲得最新的鼠標坐標,把這個x和y坐標做為圖片的top和left值就可以移動圖片了。
本例演示如何向 HTML 頁面添加背景圖片。
<html>
<body background="background.jpg">
<h3>圖像背景</h3>
<p>gif 和 jpg 文件均可用作 HTML 背景。</p>
<p>如果圖像小于頁面,圖像會進行重復。</p>
</body>
</html>
HTML基礎操作:圖片顯示
*請認真填寫需求信息,我們會在24小時內與您取得聯系。