zoukankan      html  css  js  c++  java
  • jquery “做页面滚动到某屏时改变状态标题” 所用知识点记录

    浏览器滚动条滚动时触发事件

        //浏览器滚动条滚动时触发事件
        $(window).scroll(function(){});

    浏览器窗口大小改变时触发事件

        //浏览器窗口大小改变时触发事件
        $(window).resize(function(){});

    监听所有锚点链接实现平滑移动

        //监听所有锚点链接实现平滑移动
        $('a[href*=#],area[href*=#]').click(function() {
            if (location.pathname.replace(/^//, '') == this.pathname.replace(/^//, '') && location.hostname == this.hostname) {
                var $target = $(this.hash);
                $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
                if ($target.length) {
                    var targetOffset = $target.offset().top;
                    //为提升用户体验,做出算法改进 start
                    var clientHeight    =    document.body.clientHeight;    //浏览器可视高度
                    targetOffset    =    targetOffset-(clientHeight/2)+100;
                    //end
                    $('html,body').stop(true).animate({
                        scrollTop: targetOffset
                    },
                    1000);
                return false;
                }
            }
        });

    获取某元素基于当前浏览器窗口底部的距离

    //获取某元素基于当前浏览器窗口底部的距离
    function get_element_window_bottom(choose){
        if(choose=='') return false;
        mTop = $(choose)[0].offsetTop;
        sTop = $(window).scrollTop();
        result = mTop - sTop;
        //增加一个算法提高用户体验度
        result    =    result+parseInt(document.body.clientHeight/2);
        return     result;
    }

    效果实例图

  • 相关阅读:
    大厂的面试官是如何挑人的?
    搞懂这7个Maven问题,带你吊打面试官!
    Spring Cloud Eureka 注册安全一定要做到位!
    09 webpack的介绍
    08 node.js 的使用
    07 Node.js安装及环境配置
    06-Nodejs介绍
    05-面向对象
    Mysql 的使用方法
    04-对象的单体模式
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/6194677.html
Copyright © 2011-2022 走看看