覆盖同一页面上的默认滚动行为目标

时间:2020-04-10 10:31:42

标签: javascript jquery html css scroll

我在同一页面上有一个带有导航栏的页面。当我禁用所有js插件并单击链接时,它“跳转”(没有平滑滚动)到锚定链接。

但是因为我有一个粘性标头,所以必须使用偏移量。因此,我从网上复制了这段不错的代码:

我的“导航栏”

cols = ['Province/State', 'Country/Region','Lat','Long','Date']

dfs = [df1, df2, df3]
df_merged = pd.concat([x.set_index(cols) for x in dfs], axis=1).reset_index()  
df_merged.to_csv('merged.csv', sep=',', encoding='utf-8', index=False)

html页面的一部分:

 df <- data.frame(chr=c("SWAT","SWAT","VIC","VIC","MOD16A2","MOD16A2"),
                 year=c("2001_K","2002_K","2001_K","2002_K","2001_K","2002_K"),                 
                 purulia=c(-12,0.56,-0.35,0.49,0.11,0.23),
                 bankura=c(-43,-0.56,0.35,0.74,-0.11,0.89),
                 jhargram=c(0.13,-0.12,-0.41,0.16,-0.69,0.42))
df.l <- reshape(df, [enter image description here][1]
                varying = c("purulia", "bankura", "jhargram"),
                idvar="chr",
                v.names = "NSE",
                timevar = "Locations",
                times=c("purulia", "bankura", "jhargram"),
                new.row.names=c(1:(3*nrow(df))),
                direction = "long")
library(ggplot2)
df.l$year <- factor(df.l$year)
ggplot(df.l, aes(Locations, year)) + geom_tile(aes(fill = NSE)) + 
  scale_fill_gradient(low = "white", high = "red") + facet_wrap(~chr)+ 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
<div id=myAffix>My Affix</div>
<a href="#2849">Example link</a>

当我现在单击链接时,它会平滑滚动到该部分(带有偏移量),然后它会“跳转”到没有偏移量的位置。我试图覆盖默认的滚动行为,禁用单个js插件,但它保持了这种行为。有人有主意吗?

0 个答案:

没有答案