Discuz教程网

jQuery页面滚动浮动层智能定位实例代码

[复制链接]
authicon dly 发表于 2011-9-8 16:34:13 | 显示全部楼层 |阅读模式
HTML代码:
  1. <div class="float" id="float">
  2. 我是个腼腆羞涩的浮动层...
  3. </div>
复制代码

JS代码:
  1. $.fn.smartFloat = function() {
  2. var position = function(element) {
  3. var top = element.position().top, pos = element.css("position");
  4. $(window).scroll(function() {
  5. var scrolls = $(this).scrollTop();
  6. if (scrolls > top) {
  7. if (window.XMLHttpRequest) {
  8. element.css({
  9. position: "fixed",
  10. top: 0
  11. });
  12. } else {
  13. element.css({
  14. top: scrolls
  15. });
  16. }
  17. }else {
  18. element.css({
  19. position: "absolute",
  20. top: top
  21. });
  22. }
  23. });
  24. };
  25. return $(this).each(function() {
  26. position($(this));
  27. });
  28. };
  29. //绑定
  30. $("#float").smartFloat();
复制代码



上一篇:JQuery里面的几种选择器 查找满足条件的元素$(&quot;#控件ID&quot;)
下一篇:读jQuery之十四 (触发事件核心方法)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 06:56

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表