现在的位置: 首页 > 综合 > 正文

js页面滚动浮动层智能定位(jQuery)实例页面

2013年06月17日 ⁄ 综合 ⁄ 共 976字 ⁄ 字号 评论关闭
HTML代码:

<div class="float" id="float">
    我是个腼腆羞涩的浮动层...
</div>

 

JS代码:

$.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: 
"absolute",
                    top: top
                });    
            }
        });
    };
    
return $(this).each(function() {
        position($(
this));                         
    });
};

//绑定
$("#float").smartFloat();

转至:http://www.zhangxinxu.com/wordpress/?p=1242

抱歉!评论已关闭.