最近刚刚用一点点jquery制作了这个粘性导航栏,并意识到它不起作用。当我尝试将我的代码复制到jsfiddle时,一切正常
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css\style.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open Sans">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js\scripts.js"></script>
</head>
<body>
<header onmouseover="this.style.background='white'" onmouseout="this.style.background='#e6e6e6'">
<img src="Photos\logo.png" width="210px" height="150px">
</header>
<ul class="navbar">
<li><a href="#">Model</a></li>
</ul>
<div class="main">lots of words......</div
</body>
</html>
和scripts.js文件:
var n=$(".navbar"),
ns="navbar-scrolled",
head=$('header').height();
$(window).scroll(function() {
if( $(this).scrollTop() > head) {
n.addClass(ns);
}
else {
n.removeClass(ns);
}
});
css文件与我JSFiddle
中的相同答案 0 :(得分:0)
默认情况下,JSFiddle在窗口加载时运行您的脚本,这意味着它在加载DOM之后运行。你需要自己正常做这件事。只需稍作修改即可解决问题......
$(function() {
// your code goes here
});
你只需要像这样包装你的代码......
pi@raspberrypi:~ $ docker exec -it cc55da85b915 bash
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"bash\": executable file not found in $PATH"
pi@raspberrypi:~ $ docker exec -it cc55da85b915 sh
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"sh\": executable file not found in $PATH"
还有其他方法可以做到这一点,但这将解决您的问题。