有段时间没有碰Web端了,最近做了个功能,需要做个DIV随滚动条滚动而滚动,mark一下:
源码:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>div随滚动条滚动而滚动</title> 6 <style type="text/CSS"> 7 #divContainer{width:1200px;height:1800px;border:1px solid #0000FF;margin:0px auto;} 8 /* 9 设置div固定显示在屏幕位置时,定位计算公式:10 11 left:50% + margin-left:±(页面内容部分宽度+div宽度+间隔像素)12 */13 #divMain{width:500px;height:400px;margin:0px auto;position:fixed;top:50%;left:50%;border:1px solid #ff0000;text-align:center;line-height:400px;margin:-200px 0px 0px -350px;}14 </style>15 </head>16 17 <body>18 <div id="divContainer">19 <div id="divMain">20 <span>div随滚动条滚动而滚动</span>21 </div>22 </div>23 </body>24 </html>
预览效果:
PRLCLxNKmlLWklC5r2jhNnDiXpcna5eLETdLESZo4bew4cRzbyfHt+HJ8i5Nseb71jx4OuTjH9vn5u/PN6yUr8lLbsc/vc977fN86+nnF2rVrP/vZz94EqLBihccAAADAkRDgP129erW3t7dQKBSLxdEKY2Nj2Z9l4+PjpVJpcHAwvP9upCigAdsGAAAAjoTAPBTQgG0DAAAAR0IgFwpowLYBAACAIyGQCwU0YNsAAADAkRDIhQIasG0AAADgSAjkQgEN2DYAAABwJARyoYAGbBsAAAA4EgK5UEADtg0AAAAcCYFcKKAB2wYAAACOhEAuFNCAbQMAAABHQiAXCmjAtgEAAIAjIZALBTRg2wAAAMCREMiFAhqwbQAAAOBICORCAQ3YNgAAAHAkBHKhgAZsGwAAADgSArlQQAO2DQAAABwJgVwooAHbBgAAAI6EQC4U0IBtAwAAAEdCIBcKaMC2AQAAgCMhkAsFNGDbAAAAwJEQyIUCGrBtAAAA4EgI5EIBDdg2AAAAcCQEcqGABmwbAAAA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