• 监测scroll


        $(window).scroll(function() {
            var scrollValue = $(this).scrollTop(); 
            var h=200+scrollValue;
            $('.yui3-widget.yui3-overlay.yui3-widget-positioned').css('top', h);
        });

    这里h 可以是 54  '54'  '54px' 等三种表达形式
    scrollValue 本身就是数值  无需转换

    最初我写成了这样

            var top=$('.yui3-widget.yui3-overlay.yui3-widget-positioned').css('top');
            top=parseInt(top.substr(0,top.length-2));
    
            var scrollValue = $(this).scrollTop(); 
            var h=top+scrollValue;
            h=parseInt(h);
            $('p.notice').text(h);
            $('.yui3-widget.yui3-overlay.yui3-widget-positioned').css('top', h);

    这样是不能正确控制悬浮层的位置的    

    因为我这里的h是有原本的top加上scrollTop的值   但是随着我的滚动   原本的top值就在不断的改变

    那么div本身的top在之后设定后又成为的新的top值   所以我这样做  是top只不断的重复计算了

  • 相关阅读:
    最短路径问题/Spfa
    cddiv/数组维护
    cfdiv2/c/找规律
    Codeforces Round #343 (Div. 2)【A,B水题】
    POJ 2135_Farm Tour
    POJ 3469_Dual Core CPU
    POJ 3469_Dual Core CPU
    POJ 3281_Dining
    POJ 3281_Dining
    POJ 3041_Asteroids
  • 原文地址:https://www.cnblogs.com/cart55free99/p/3561866.html
Copyright © 2020-2023  润新知