博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
滑动鼠标,固定导航栏一直闪烁
阅读量:3948 次
发布时间:2019-05-24

本文共 357 字,大约阅读时间需要 1 分钟。

需求:当页面滚动距离大于某一值时,导航栏固定在页面顶部。向上滑动,当滚动距离小于某一值时,导航回到原位置。

问题:每次向下滑动鼠标,固定导航栏一直闪烁。

怀疑

  1. 获取导航栏位置时,不要在scroll事件里获得,在scroll事件外获得。因为在滚动鼠标时,一直在实时查询,导致闪烁。
  2. 本来的导航栏在滚动距离大于某一值时,该导航栏直接设置了display:none,元素直接不见了,获取的页面高度就需要重新减去这个元素高度,从而导致闪烁。建议页面本来的导航栏和固定导航设置成两个div,当高度大于某一值时,本来的导航栏设置是visibility:hidden。这样元素依然在页面中占据一定的位置,但是看不见。当需要时,再设置导航栏visibility:visible

后来实验了一下,第二种导致页面闪烁的可能性更大。

转载地址:http://sdhwi.baihongyu.com/

你可能感兴趣的文章
Creating an Android Project
查看>>
Running Your App (android)
查看>>
Starting Another Activity
查看>>
Starting an Activity
查看>>
Stopping and Restarting an Activity
查看>>
Using the Support Library
查看>>
Creating a Fragment
查看>>
Building a Flexible UI
查看>>
Communicating with Other Fragments
查看>>
Saving Key-Value Sets
查看>>
Saving Files
查看>>
Saving Data in SQL Databases
查看>>
Sending the User to Another App
查看>>
Getting a Result from an Activity
查看>>
Allowing Other Apps to Start Your Activity
查看>>
Using the Location Manager
查看>>
Obtaining the Current Location
查看>>
Displaying the Location Address
查看>>
Connecting to the Network
查看>>
Managing Network Usage
查看>>