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;
    }

    效果实例图

  • 相关阅读:
    Socket原理与编程基础
    Hello cnblogs
    c# List 分页问题
    chrome下载Word失败问题
    前端时间Date显示问题踩坑
    Vue跳转同一界面多次,使用不同数据进行渲染
    Hadoop在Linux环境下的配置
    RabbitMQ下载安装
    Codeforces 527 C. Glass Carving
    python压缩、解压文件
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/6194677.html
Copyright © 2011-2022 走看看