css+div 如何实现客服窗口,在某一个id的位置显示并且悬浮

html-css011

css+div 如何实现客服窗口,在某一个id的位置显示并且悬浮,第1张

可以使用css fixed,

例:

<style>

.window{

width:100px

height:50px

position:fixedright:0top:45%//关键是这一行,设置窗口的位置,如果网页层较多,应该用z-index将窗口div置于顶层,否则会被遮盖;

z-index:999

}

</style>

<div class="window">

客服窗口,点击与客服咨询

</div>

一般情况下都是用CSS的fixed固定定位,但不兼容IE6,在IE6下,用absolute方式。

下面给出简单的兼容写法代码实现。仅供参考:

<style>    

*{margin:0px padding:0px}    

body {height:2000px}    

div {width:100px height:100px background:#ccc position:absolute bottom:0px right:0px}    

</style>    

<script>    

window.onload=function(){    

var oDiv = document.getElementById('div1')    

if(window.navigator.userAgent.indexOf('MSIE 6') != -1)    

{    

window.onscroll = function(){    

var scrollTop = document.documentElement.scrollTop || document.body.scrollTop    

var top = document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop      

oDiv.style.top = top + 'px'    

}

}    

else    

{    

oDiv.style.position='fixed'    

}    

}    

</script>

<div style="right:0position:fixed_position:absolutebottom:100px" id="xf_01"><img src="images/1.jpg"><div style="text-align:rightheight:20px"><span onclick="document.getElementById('xf_01').style.display='none'" style="cursor:handpadding-left:100px"><a>关闭</a></span></div></div>

把你的问题去百度一搜,有很多的