4

I need to scroll in a window but my window height is too small to scroll. Is it possible to scroll when the height of container is too small to see the scrollbar. Here is my code to scroll:

setTimeout(function(){
  $(window).scrollTop($(window).scrollTop()+1);
  $(window).scrollTop($(window).scrollTop()-1);
}, 800);

I need to scroll window or body even if height of it is less than 100px.

3
  • 1
    Scroll it to where? It's unclear what you are trying to do. Commented Apr 17, 2015 at 14:21
  • If you are talking about triggering scroll event that you simply need to use $(window).scroll(); w3schools.com/jquery/event_scroll.asp Commented Apr 17, 2015 at 14:23
  • scroll to where ? and how ? could you share your html so that we can replicate Commented Apr 17, 2015 at 14:24

4 Answers 4

3

I believe you want to set a min-height of 110% on html in your CSS. I would do:

html {
  min-height: 110%;
}

Here's a demo: http://jsbin.com/sebago/1/edit?html,css,output

Sign up to request clarification or add additional context in comments.

Comments

0

If you define a fixed height in your element, then you can use overflow:scroll to enable scroll.

Comments

0

You need first hide the scroll bar to do not take space (because you don't have too much space in the element), you can make that with the next css:

#elementId{ 
   overflow: hidden;
}

Then you need to bind the mousewheel event over the 'small' element and trigger a function to manually scroll your element, you can do that with the next jQuery code:

$('#elementId').bind('DOMMouseScroll mousewheel', function(e) {
    $('#elementId').scrollTop($('#elementId').scrollTop()+1);
});

This example is simplified just to bind the mousewheel event in general, to know if it is up or down you can use the jQuery Mouse Wheel Plugin that you can get here.

1 Comment

'DOMMouseScroll' binding is for Firefox browsers
0

To see scrollbar, just use CSS property overflow:scroll; on your container.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.