[英]Sidebar with offset doesn't work. What do I wrong?
Hi I use stickToTop ( http://sdbondi.github.io/jquery-sticktotop/ ) from fixate.it to make an sidebar that will move when you scroll down. 嗨,我使用fixate.it的stickToTop( http://sdbondi.github.io/jquery-sticktotop/ )制作了一个侧栏,当您向下滚动时,该侧栏将移动。
Here is my JSfiddle: http://jsfiddle.net/f6VwP/ 这是我的JSfiddle: http : //jsfiddle.net/f6VwP/
Everything there is going just fine..just how I want it, but when I use it in my code program it doesn't work at all. 那里的一切都很好,..就是我想要的,但是当我在代码程序中使用它时,它根本无法工作。
I think it has something to do how I put the js code in the index.html but I am not sure. 我认为这与我将js代码放入index.html的方式有关,但我不确定。 I put this script link in the body:
我将此脚本链接放在正文中:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://sdbondi.github.io/jquery-sticktotop/jquery-sticktotop.js"></script>
My other javascript I made in an apart document called: jquery.stickToTop.js this code is in te head code like this: 我在另一个文档中制作的另一个JavaScript名为:jquery.stickToTop.js,此代码在以下代码中是这样的:
<script type="text/javascript" src="js/jquery.stickToTop.js"></script>
The code of the stickToTop.js is: stickToTop.js的代码为:
;(function () {
var navHeight = $('.sticky').outerHeight(true);
$('.js-sticky').stickToTop({ offset: {top: 50}});
})();
So, what do I wrong? 那么,我错了什么呢? Thanks!
谢谢!
everything is fine in fiddle because it presumes the jQuery.ready function I suppose you have to change your jQuery code to this: 一切都很好,因为它假定了jQuery.ready函数,我想您必须将jQuery代码更改为此:
$(function () {
var navHeight = $('.sticky').outerHeight(true);
$('.js-sticky').stickToTop({ offset: {top: 50}});
});
let me know how it goes. 让我知道事情的后续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.