div层的定位以及消息提示的淡出效果

来源:互联网 发布:淘宝设置图盾 编辑:程序博客网 时间:2024/06/05 16:29

<div id="popupContact" >xx</div>
//层的定位
var divId=document.getElementById("popupContact");
divId.style.top=(document.body.clientHeight-divId.clientHeight)/2+document.body.scrollTop;
divId.style.left=(document.body.clientWidth-divId.clientWidth)/2+document.body.scrollLeft;
//随滚动条滚动事件
function play(){
     var divId=document.getElementById("popupContact");
     divId.style.left=(document.body.clientWidth-divId.clientWidth)/2+document.body.scrollLeft;  
     divId.style.top=(document.body.clientHeight-divId.clientHeight)/2+document.body.scrollTop;
}
window.onscroll=play;

***************************************************

语法:$(selector).fadeOut(speed,callback)
speed 可选。规定元素从可见到隐藏的速度。默认为 "normal"。
可能的值:
毫秒 (比如 1500)
"slow"
"normal"
"fast"
在设置速度的情况下,元素从可见到隐藏的过程中,会逐渐地改变其透明度(这样会创造淡出效果)。
callback 可选。fadeOut 函数执行完之后,要执行的函数。
如需学习更多有关 callback 的内容,请访问我们的 jQuery Callback 这一章。
除非设置了 speed 参数,否则不能设置该参数。
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
  $("p").fadeOut(1000);    //使用淡出效果来隐藏一个 <p> 元素
  });
  $(".btn2").click(function(){
 $("p").fadeIn(1000);
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button class="btn1">Hide</button>
<button class="btn2">Show</button>
</body>
</html>

*********************************************

 function showTips( tips ){ 
  
     var height = document.body.clientHeight/4+document.body.scrollTop;
     var windowWidth  = document.documentElement.clientWidth; 
     var tipsDiv = '<div class="tipsClass">' + tips + '</div>'; 
     $('body').append( tipsDiv ); 
     $('div.tipsClass').css({ 
         'top'       : height + 'px', 
         'left'      : (windowWidth/2)-(tips.length*13/2) + 'px', 
         'position'  : 'absolute', 
         'padding'   : '3px 5px', 
         'background': '#8FBC8F', 
         'font-size' : 12 + 'px', 
         'margin'    : '0 auto', 
         'text-align': 'center', 
         'width'     : 'auto', 
         'color'     : '#fff', 
         'opacity'   : '0.8'
     }).show(); 
     $('div.tipsClass').fadeOut(2000);
     //setTimeout( function(){$('div.tipsClass').fadeOut();}, ( 2 * 1000 ) ); 
 }