多瀏覽器支持的右下角浮動窗口
更新時間:2010年04月01日 00:37:36 作者:
支持各種瀏覽器的右下角浮動窗口,需要的朋友可以參考下。
復制代碼 代碼如下:
<script>
function $(id)
{
return document.getElementById(id);
}
var LoginUI = !!window.LoginUI || {};
LoginUI.getViewportWidth = function(){
var width=0;
if(document.documentElement && document.documentElement.clientWidth){
width=document.documentElement.clientWidth;}
else if(document.body && document.body.clientWidth){
width=document.body.clientWidth;}
else if(window.innerWidth){
width=window.innerWidth-18;}
return width;
}
LoginUI.getViewportHeight = function() {
var height=0;
if(window.innerHeight){
height=window.innerHeight-18;}
else if(document.documentElement&&document.documentElement.clientHeight){
height=document.documentElement.clientHeight;}
else if(document.body&&document.body.clientHeight){
height=document.body.clientHeight;}
return height;
}
LoginUI.getViewportScrollX = function(){
var scrollX=0;
if(document.documentElement&&document.documentElement.scrollLeft){
scrollX=document.documentElement.scrollLeft;}
else if(document.body&&document.body.scrollLeft){
scrollX=document.body.scrollLeft;}
else if(window.pageXOffset){
scrollX=window.pageXOffset;}
else if(window.scrollX){
scrollX=window.scrollX;}
return scrollX;
}
LoginUI.getViewportScrollY=function() {
var scrollY=0;
if(document.documentElement&&document.documentElement.scrollTop){
scrollY=document.documentElement.scrollTop;}
else if(document.body&&document.body.scrollTop){
scrollY=document.body.scrollTop;}
else if(window.pageYOffset){
scrollY=window.pageYOffset;}
else if(window.scrollY){
scrollY=window.scrollY;}
return scrollY;
}
function scrollMsgTip()
{
var t = LoginUI.getViewportHeight() + LoginUI.getViewportScrollY() - $("msgtip").offsetHeight;
$("msgtip").style.top = t + "px";
$("msgtip").style.left = LoginUI.getViewportWidth() + LoginUI.getViewportScrollX() - $("msgtip").offsetWidth + "px";
}
function scrollTip()
{
scrollMsgTip()
}
window.onload = window.onscroll = scrollTip;
</script>
以上是js代碼,下面是浮動的窗口
復制代碼 代碼如下:
<div style='position:absolute;top:0;left:0;width:300px;height:180px;border:3px double #AAA' id='msgtip'>dfddfdf</div>
相關文章
window.event.srcElement 得到事件源對象
window.event.srcElement 得到事件源對象代碼,大家可以參考腳本之家以前發(fā)的代碼,多瀏覽兼容的。2009-05-05JavaScript中函數(shù)聲明與函數(shù)表達式的區(qū)別詳解
可能很多朋友只知道兩種聲明方式一個是函數(shù)聲明一個是函數(shù)表達式,具體有什么不同沒能說得很好。事實上,JavaScript的解析器對函數(shù)聲明與函數(shù)表達式并不是一視同仁地對待的。下面看看這兩者到底有什么不同。2016-08-08uniapp頁面通訊講解之uni.$emit、uni.$on、uni.$once和uni.$off
uni-app?是一個使用vue.js開發(fā)所有前端應用的框架,下面這篇文章主要給大家介紹了關于uniapp頁面通訊之uni.$emit、uni.$on、uni.$once和uni.$off的相關資料,需要的朋友可以參考下2022-09-09