• 页面滚动固定


    实例代码:

     1 $(document).scroll(function () {
     2 
     3         var $leftBox = $('.lFixedBlock'),
     4                 $rightBox = $('.rFixedBlock'),
     5                 leftBoxHeight = $leftBox.height(),
     6                 rightBoxHeight = $rightBox.height(),
     7                 windowHeight = $(window).height(),
     8                 scrollTop = $(document).scrollTop(),
     9                 diffHeight = leftBoxHeight - rightBoxHeight;
    10         if (diffHeight > 0) {
    11             if ((scrollTop + windowHeight) > (leftBoxHeight + $leftBox.offset().top)) {
    12                 $rightBox.css({'position': 'fixed', 'bottom': (scrollTop + windowHeight) - (leftBoxHeight + $leftBox.offset().top)});
    13             } else if ((scrollTop + windowHeight) > (rightBoxHeight + $leftBox.offset().top)) {
    14                 $rightBox.css({'position': 'fixed', 'bottom': 0});
    15             } else {
    16                 $rightBox.css({'position': 'static', 'bottom': 'auto'});
    17             }
    18         } else {
    19             if ((scrollTop + windowHeight) > (rightBoxHeight + $rightBox.offset().top)) {
    20                 $leftBox.css({'position': 'fixed', 'bottom': (scrollTop + windowHeight) - (rightBoxHeight + $rightBox.offset().top)});
    21             } else if ((scrollTop + windowHeight) > (leftBoxHeight + $rightBox.offset().top)) {
    22                 $leftBox.css({'position': 'fixed', 'bottom': 0});
    23             } else {
    24                 $leftBox.css({'position': 'static', 'bottom': 'auto'});
    25             }
    26         }
    27 
    28     });
  • 相关阅读:
    Java基础-Object通用方法
    Java基础-关键字
    Java基础-运算
    Java基础-String
    Java基础-数据类型
    GCN-GAN:对加权动态网络的非线性时间链路预测模型
    长短期记忆(long short-term memory, LSTM)
    CSP 201604-1 折点计数
    介绍一个好东西C++11
    malloc free使用规范
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3503703.html
Copyright © 2020-2023  润新知