自定义 JavaScript 在 Chrome 中不起作用
Custom Javascript not working in Chrome
浏览了很多,摆弄了很多。得出的结论是,别人可能会看到我视而不见的错误。
代码应该根据窗口高度、侧边栏高度、内容高度等移动侧边栏。
这是代码:
$(document).ready(function() {
var windowheight = $(window).height();
var identheight = $(".ident").height();
var sidebarheight = $(".sidebar").height();
var mainheight = $(".main").height();
var pos = $(window).scrollTop();
var diff = (((sidebarheight + 20) + identheight) - windowheight);
var cur = ((sidebarheight + 20) + (pos - diff)) - 2;
var max = (mainheight + 30);
contentScroll();
$(window).resize(function(){
windowheight = $(window).height();
identheight = $(".ident").height();
sidebarheight = $(".sidebar").height();
mainheight = $(".main").height();
pos = $(window).scrollTop();
diff = (((sidebarheight + 20) + identheight) - windowheight);
cur = (sidebarheight + 20) + (pos - diff);
max = (mainheight + 30);
contentScroll();
});
$(window).scroll(function (){
pos = $(window).scrollTop();
diff = (((sidebarheight + 20) + identheight) - windowheight);
cur = (sidebarheight + 20) + (pos - diff);
max = (mainheight + 30);
contentScroll();
});
function contentScroll() {
if (sidebarheight < mainheight) {
if (diff < identheight) {
if (pos >= identheight) {
$('.sidebar').css({
'margin-top' : (pos - identheight) + 'px'
});
}
} else {
if (pos >= diff && cur <= max) {
$('.sidebar').css({
'margin-top' : (pos - diff) + 'px'
});
}
if (pos <= diff) {
$('.sidebar').css({
'margin-top' : '0px'
});
}
}
}
}
});
我知道它并不完美,它仍处于艰难阶段。它在FireFox
中工作得很好,但在chrome
中则不然。正在调用该函数(使用警报进行测试)。它只是什么都不做。
可能是关于chrome
阅读语法的不同。
如果有人看到我的错误会好心地指出我,我已经太久了,不能继续为此开脑袋。
这是有问题的模拟网站:http://klok-bremen.de/fff/
使用 $(window).
load 而不是 $(document).ready,因为父元素的高度在图像加载后会发生变化。
相关文章:
- XMLHttpRequest在移动设备上的chrome上不起作用
- ng disabled在chrome中不起作用.按钮在角度上未禁用
- 鼠标输入在 YUI 的 chrome 中不起作用
- Javascript的某些部分在Chrome中不起作用,但在其他浏览器中可以完美工作
- HTML5视频链接在Chrome中不起作用
- jQuery克隆函数在chrome中不起作用
- jQuery place attr src在Chrome中不起作用
- chrome中的onmouseover(下拉选项标记)事件不起作用-php,javascript
- .ajax调用在chrome中不起作用
- Javascript/AAJAX在Opera中不起作用,在FF/IE/Chrome中完美工作
- 正在处理在chrome扩展中不起作用的js
- MediaSource API demo不起作用(Chrome)
- Chrome 中表格的 CSV 导出不起作用 - JavaScript/AngularJS
- $.getJSON 在 Chrome 和 Safari 中不起作用
- OnClick 事件在 Chrome 中不起作用
- getUserMedia 在 Chrome v50.0.2661.86 上不起作用
- dataTransfer.set拖放的数据在chrome中不起作用
- 简单的鼠标悬停在 Chrome 中不起作用
- window.close();在Chrome和Firefox中不起作用
- SoundCloud widget .play() 方法在选项卡在后台时不起作用 (Chrome)