请教各位一个div浮动的样式问题_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:10:22
原创
1105人浏览过

大家好,我想实现这么一个效果,就是滚动条往下拉的时候当拉到一个div,而且此div下面已经没有内容了,那么如果我继续往下拉这个div会随着滚动条往下同步移动,有没有人告诉我怎么实现啊,有些实现方式div跳动的不好看,我在网上看到一个网站http://www.kl688.com/这里的右边最下面那个广告就是这个效果,求指导,谢谢啊

PatentPal专利申请写作
PatentPal专利申请写作

AI软件来为专利申请自动生成内容

PatentPal专利申请写作 13
查看详情 PatentPal专利申请写作

回复讨论(解决方案)

页面滚动超过固有位置时加一个fixed的样式就可以了

<!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>  <title>滚动超过时固定位置</title>  <script type="text/javascript" src="js/jquery-1.6.4.min.js" ></script>  <style type="text/css" >    .fixed-top /* position fixed Top */{position:fixed;bottom:auto;top:0; }   * html .fixed-top /* IE6 position fixed Top */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}    </style></head><body><div style="height:500px;border:1px solid green;">some text before</div> <div id="fixpass" style="border:1px solid red; background-color:gray;width:100%;">这是一些文字,滚动超过时将固定</div><div style="height:1000px;border:1px solid blue;position:relative;">some text after<div style="position:absolute;bottom:0;">some end text</div></div></body>  <script type="text/javascript">      var $window = $(window),      $stickyEl = $('#fixpass');      var elTop = $stickyEl.offset().top;      $window.scroll(function() {        var windowTop = $window.scrollTop();        $stickyEl.toggleClass('fixed-top', windowTop > elTop);      });  </script></html>
登录后复制

页面滚动超过固有位置时加一个fixed的样式就可以了
HTML code

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

我刚才试了下,没有固定,你再试试,是不是忘记写东西了?

我各种游览器都测试过的
你不会没有下jquery吧

页面滚动超过固有位置时加一个fixed的样式就可以了
HTML code

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script></script>

/* IE6 position fixed Top
亮点呀。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">*{margin:0;padding:0;}body{background:#242424;color:#ccc;font-family:Verdana, Arial, Helvetica, sans-serif;line-height:150%;}#fixed{position:fixed;top:5em;right:0;}  <!-- 针对IE7、Opera、Firefox一行搞定 --></style><!-- IE6中利用容器对溢出内容的处理方式来实现的 --><!-- fixed元素的绝对位置是相对于HTML元素来说,滚动条是body元素的,这是设置right:17px的原因 --><!--[if IE 6]><style type="text/css">html{overflow:hidden;}body{height:100%;overflow:auto;}#fixed{position:absolute;right:17px;}</style><![endif]--><!--[if lt IE 6]><style type="text/css">#fixed{position:absolute;top:expression(eval(document.body.scrollTop + 50));}</style><![endif]--></head><body><div id="wrapper"><ul><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li><li>随网之舞</li></ul></div><div id="fixed"><h2>{position:fixed}</h2></div></body></html>
登录后复制

我各种游览器都测试过的
你不会没有下jquery吧
晕,没注意你用到了jquery,我测试过了,没问题,不过放在我网站里面还是没效果,应该是网页中其他的一些样式有影响,还是不用这个效果了。总之谢谢你啊!

JScript code


nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


这个应该也可以,我没试,感谢啊!

有空欢迎看看我的网站- 好望角,感谢各位!

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号