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

    效果实例图

  • 相关阅读:
    现在SimpleMemory的CSS(by BNDong)
    I AK IOI
    最大半联通子图
    曾经SimpleMemory的CSS
    幼儿园战争
    炸掉卡西欧991CNX
    LuoguP1131选择客栈
    2019CSP-S2养成任务
    NOIP2013&NOIP2018&USACO 三倍经验铺路题巧妙解法
    NOIP2018D2T1 旅行
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/6194677.html
Copyright © 2011-2022 走看看