欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于JS实现二维码图片固定在右下角某处并跟随滚动条滚动

程序员文章站 2022-06-10 16:58:36
1、准备一张二维码图片,大小、图片自己定义我这里用的宽度和高度都是253,名称weixin.jpg

1、准备一张二维码图片,大小、图片自己定义我这里用的宽度和高度都是253,名称weixin.jpg

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<title>二维码图片固定在右下角某处并跟随滚动条滚动</title> 
</head> 
<body> 
<div style="width:1000px; height:1000px;">二维码图片固定在右下角某处并跟随滚动条滚动</div> 
<script language="javascript"> 
function wx_scroll(){  
 var toph=-80; 
 var leftw=10; 
 var sheight,swidth,cheight; 
 //alert(document.documentelement.clientwidth); 
 (document.body.scrollleft==0)?swidth=document.documentelement.scrollleft + document.documentelement.clientwidth - 260 :swidth=document.body.scrollleft+ document.documentelement.clientwidth - 260 ; 
 (document.body.scrolltop==0)?sheight=document.documentelement.scrolltop+ document.documentelement.clientheight - 260 :sheight=document.body.scrolltop+ document.documentelement.clientheight - 260; 
 document.getelementbyid("bar_float").style.left=eval(swidth+leftw) +"px"; 
 document.getelementbyid("bar_float").style.top=eval(sheight+toph) +"px"; 
} 
setinterval("wx_scroll()",100); 
</script> 
<div id="bar_float" style="position: absolute; display:block; z-index: 10000; left: 1216px; top: -80px;"> 
<div id="staytopleft"> 
 <table cellspacing="0" cellpadding="0" border="0"> 
 <tbody> 
 <tr> 
  <td colspan="2" valign="top"><img src="weixin.jpg" width="253" height="253" border="0"></td> 
  </tr> 
  <tr> 
 </table></div> 
</div> 
</body> 
</html> 

以上所述是小编给大家介绍的基于js实现二维码图片固定在右下角某处并跟随滚动条滚动,希望对大家有所帮助