不知道如何将Javascript代码添加到Tumblr

Not sure how to add Javascript code to Tumblr

本文关键字:添加 Tumblr 代码 Javascript 不知道      更新时间:2023-09-26

我从这里得到了代码,这是rossipedia的主要解决方案:固定侧边栏直到div

这是我的 Tumblr 页面和脚本影响的代码部分(main 替换为内容):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
...
<style type="text/css">
#sidebarwrap {
  margin: 0 0 1.5em;
  width: 16.2em;
  float: left;
  position: relative;
}
 #sidebar {
  margin: 0 0 1.5em;
  width: 16em;
  height: 570px;
  position: absolute;
}
#sidebar.fixed {
  position: fixed;
  top: 0;
}
#footer {
  border-top: 4px solid {color:Footer Border};
  background: {color:Footer Background};
  color: {color:Background};
  clear: both;
  margin: 0;
  overflow: auto;
  padding: 0 0.5em;
}
#content {
  margin-bottom: 4.5em;
  margin-left: 18.5em;
  min-width: 500px;
  min-height: 550px;
}
</style>
</head>

身体

<body>
<div id="contain">
    <div id="sidebarwrap">
    <div id="sidebar">
    ...Stuff...
    </div>
    </div>
    <div id="content">
    ...Stuff...
    </div>
</div>
<div id="footer">
<div id="footer-container">
...Stuff...
</div>
</div>

然后,我将脚本包含在/body 之前,如下所示:

<script type="text/javascript">
    ...Script...
</script>

我一直在检查拼写并确保一切正常,但这一切都不起作用。至少不是那个JS。我使用的其他JS工作得很好...该脚本应该让我的侧边栏与用户一起滚动,然后在重叠页脚之前停止。然而,脚本的行为就像它甚至不存在一样,侧边栏没有移动一英寸......哎呀,我什至在其小提琴页面上篡改了原始版本,使其与我的页面具有相同的布局和顺序,并且它仍然运行良好。

我错过了什么吗?每个人都在谈论 JQuery,我不完全确定那是什么,或者我是否应该使用它......如果有人能帮助我看到我做错了什么,我将不胜感激!:会

看起来你确实需要在页面上加载jQuery才能使用你添加的代码。 jQuery是一个JavaScript库;它提供了"$"函数。

要在页面中加载 jQuery,请在固定侧边栏代码之前添加以下内容:

<!-- Note that we have a closing tag right after the opening tag here. -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    // Your code here
</script>