js网页如何绝对定位

JavaScript012

js网页如何绝对定位,第1张

js网页绝对定位/相对定位,参考如下:

<html>

<head>

<meta http-equiv="content-type" content="text/htmlcharset=GB2312" />

<title>CSS和Js演示网页绝对定位与相对定位</title>

<!-- 通用样式表 -->

<style>

* { font-size:12pxfont-family:宋体, Arial} /*规定了所有的字体样式*/

body { overflow:autoborder-style:nonemargin:0pxpadding:0px}

.tools { position:absolutetop:180pxleft:10px}

#abs { position:absoluteleft:10pxtop:10pxwidth:150pxheight:150pxbackground-color:buttonfacepadding:10px}

#rel { position:relativeleft:170pxtop:40pxwidth:150pxheight:120pxbackground-color:buttonfacepadding:10px}

</style>

<script>

function logEvent(){

$("ipt_x").value = event.x

$("ipt_y").value = event.y

$("ipt_x2").value = event.clientX

$("ipt_y2").value = event.clientY

}

function $(str){ return(document.getElementById(str))}

window.onload = function(){

document.onmousemove = logEvent

}

</script>

</head>

<body>

<div id="abs">绝对定位</div>

<div id="rel">相对定位</div>

<div class="tools">

event.x <input id="ipt_x" size="15" >

event.y <input id="ipt_y" size="15" >

<br/>

event.clientX <input id="ipt_x2" size="9" >

event.clientY <input id="ipt_y2" size="9" >

</div>

</body>

</html>

在现行的网站应用中URL重定向的应用有很多:

404页面处理、网址改变、多个网站地址等;

本质上就是将当前使用者的网址从一个网址导向到另外的一个网址上面去;

实现重定向的方式有很多种,有服务器端配置、后端程序重定向处理、前端js重定向;

前端重定向的实现:

在众多的BOM对象中,location算是最重要的对象之一了,使用location可以通过多种方式来改变浏览器的位置,如:

location.assign("http://www.baidu.com")

window.location="http://www.baidu.com"

location.href="http://www.baidu.com"

另外修改location对象的其他属性也可以改变当前加载的页面。