一个固定的div,带有Javascript,可在窗口太小时滚动. DOC TYPE问题 [英] A fixed div with Javascript to scroll when a window is too small. DOC TYPE issue

查看:83
本文介绍了一个固定的div,带有Javascript,可在窗口太小时滚动. DOC TYPE问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个必须为菜单使用固定DIV的网站上工作. www.atelier2architecten.nl/index2.php

I'm working on a site where I have to use a fixed DIV for the menu. www.atelier2architecten.nl/index2.php

我正在尝试找到一种方法来使固定div水平滚动. 因为,当je缩小浏览器窗口时,您无法单击窗口外部的按钮.

I'm trying to find a way to let the fixed div scroll horizontal. Because, when je make your browser window smaller you can't click the buttons that are outside te window.

我找到了一些jquery解决方案.但是这些包括动画.我的客户不想要那个.它必须保持固定状态.

I found some jquery solution. But those include animation. My client doesn't want that. it has to stay fixed.

我也在该站点上找到了一个很好的解决方案,但是当我在代码中使用DOC TYPE时,它不起作用. (我的CSS需要它)

I also found a great solution on this site But it doens't work when i use a DOC TYPE in my code. ( I need that for my CSS )

这是与任何DOC TYPE都不兼容的代码:

This is the code that doens't work with any DOC TYPE:

function hscrollbar() {

var left = 
    /* window.pageXOffset should work for most recent browsers: */
    window.pageXOffset ? window.pageXOffset : 
    /* If it DOESN'T, let's try this: */
    document.documentElement.scrollLeft ? document.documentElement.scrollLeft : 
    /* And if THAT didn't work: */
    document.body.scrollLeft;
/* Now that we have the horizontal scroll position, set #footpanel's left 
   position to NEGATIVE the value, so it APPEARS to follow the scroll: */
document.getElementById('menu').style.left = -left;
}
window.onscroll = hscrollbar; /* Call the function when the user scrolls */
window.onresize = hscrollbar; /* Call the function when the window resizes */

我希望有人可以帮助我.当我不使用DOC TYPE时,它可以在google chrome上完美运行.但是IE仍然是问题所在.

I hope someone can help me with this. When i don't use a DOC TYPE it works perfectly on google chrome. But IE, as always, is the problem.

向托比亚斯致敬

推荐答案

您是否尝试过此方法:

$(window).scroll(function () {
   $('#menu').css('left', -($(window).scrollLeft()));
});

在FF和Chrome中进行了测试.

Tested in FF and Chrome.

P.S.需要jQuery

P.S. Needs jQuery

这篇关于一个固定的div,带有Javascript,可在窗口太小时滚动. DOC TYPE问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆