js 漂浮窗体 上下浮动 静止
作者:朱尚 / 日期:2013-12-07 / 分类:JavaScript / 浏览:1749
<script>
    //float
    $.fn.smartFloatt = function () {
        var position = function (element) {
            var top = element.position().top, pos = element.css("position");
            $(window).scroll(function () {
                var scrolls = $(this).scrollTop();
                if (scrolls > (top - 200)) {
                    if (window.XMLHttpRequest) {
                        element.css({
                            position: "fixed",
                            top: 200
                        });
                    } else {
                        element.css({
                            top: scrolls
                        });
                    }
                } else {
                    element.css({
                        position: pos,
                        top: top
                    });
                }
            });
        };
        return $(this).each(function () {
            position($(this));
        });
    };
    function hidead() {
        document.getElementById("sidebar_w").style.visibility = "hidden";
    }
</script>
<div class="sidebar_w" id="sidebar_w" style="position: absolute; left: 5px; top: 200px;">
    <img src="../images/2010279242.png" /><br />
    <div style="text-align: center;">
        <img src="../images/close.gif" style="cursor: pointer;" alt="点击 关闭" onclick="hidead()" /></div>
</div>
<script type="text/javascript">
    $(".sidebar_w").smartFloatt();
</script>

点击预览

上一篇:JS判断浏览器类型
下一篇:JS 验证大全
本文标签: 浮动 float 漂浮
本文链接:http://www.banzhuan.net/detail/34