A fixed div with Javascript to scroll when a window is too small. DOC TYPE issue

一世执手 提交于 2019-12-12 04:19:49

问题


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

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.

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

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 )

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 */

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.

Greeting Tobias


回答1:


Have you tried this:

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

Tested in FF and Chrome.

P.S. Needs jQuery



来源:https://stackoverflow.com/questions/10054588/a-fixed-div-with-javascript-to-scroll-when-a-window-is-too-small-doc-type-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!