zoukankan      html  css  js  c++  java
  • juery悬浮框

    现在的淘宝啊,京东啊等很多平台都用到了一个技术,就是当页面下拉时,某个div会一直悬浮在页面顶端。具体代码如下
    <p>jQuery实现页面滚动时层智能浮动定位</p>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery实现页面滚动时层智能浮动定位</title>
    <style type="text/css">
    *{ margin:0; padding:0;}
    body { font:12px/1.8 Arial; color:#666;height: 2000px}
    .go-back{ text-align:center; border-top:1px dashed #ccc; padding:10px; margin-top:20px; font-size:40px;}
    .wrap{border:1px dashed #ccc; background:#f8f8f8; padding:20px;}

    .float{80px; padding:10px; border:1px solid #ffecb0; background-color:#fffee0; -moz-box-shadow:1px 1px 2px rgba(0,0,0,.2); -webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2); box-shadow:1px 1px 2px rgba(0,0,0,.2); position:absolute; right:10%; top:131px;}
    </style>
    <script type="text/javascript" src="jquery.js"></script>

    </head>
    <body>


    <div class="wrap">

    <div class="float" id="float">哥赖这儿了</div>

    </div>
    <script type="text/javascript">
    $.fn.smartFloat = function() {
        var position = function(element) {
            var top = element.position().top, pos = element.css("position");
            $(window).scroll(function() {
                var scrolls = $(this).scrollTop();
                if (scrolls > top) {
                    if (window.XMLHttpRequest) {
                        element.css({
                            position: "fixed",
                            top: 0
                        });    
                    } else {
                        element.css({
                            top: scrolls
                        });    
                    }
                }else {
                    element.css({
                        position: pos,
                        top: top
                    });    
                }
            });
    };
        return $(this).each(function() {
            position($(this));                        
        });
    };
    //绑定
    $("#float").smartFloat();
    </script>
        


    </body>
    </html>

  • 相关阅读:
    泛型系列<9>:使用相应的泛型版本替换Hashtable
    泛型系列<2> 创建泛型类
    泛型系列<5>:链表的实现
    泛型系列<4>使用相应的泛型版本替换Stack和Queue
    泛型系列<8>:使用泛型创建只读集合
    Visual Studio统计有效代码行数
    C++11 现代C++风格的新元素(转)
    神秘海域:顶级工作室“顽皮狗”成长史(中)
    沸腾十五年TX
    为你解惑之WPF经典9问详解
  • 原文地址:https://www.cnblogs.com/lightinblack/p/3633275.html
Copyright © 2011-2022 走看看