简体   繁体   English

带有偏移的边栏不起作用。 我怎么了

[英]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.

相关问题 将obj-c类传递给javascript不起作用。 我究竟做错了什么? - Passing obj-c class to javascript doesn't work. What am I doing wrong? JSF 2.2表单上的tagmanager.js不起作用。 我究竟做错了什么? - tagmanager.js on JSF 2.2 form doesn't work. What am I doing wrong? 在一条线上推动和取消移动是行不通的。 我究竟做错了什么? - pushing and unshifting in one line doesn't work. what am i doing wrong? 我为自动化 web 组件创建而创建的 Javascript function 不起作用。 怎么了? - The Javascript function i created to automate web component creation doesn't work. What's wrong? Angular LightBox不起作用。 我做错了什么? - Angular LightBox doesnt work. What do I do wrong? 将代码移至函数中。 现在不起作用。 怎么了? - Moved code into a function. Now doesn't work. What's wrong? 正则表达式不起作用。 我的代码有什么问题? 谁能帮我解决这个问题 - Regex doesn't work. What's wrong with my code? Can anyone help me fix this 将 google 扩展数据保存到本地存储的代码不起作用。 怎么了? - Code for saving google extension data to local storage doesn't work. What is wrong? AJAX更新面板不起作用。 请帮助我找出我在哪里错...? - AJAX Update Panel Doesn't Work. Please help me finding where am I wrong…? 我的 HTML 按钮不起作用。 哪里不对了? - My HTML button doesn't work. Anything wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM