Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling content within an overflow:hidden div

I have 5 .kids in my #parent and I want to be able to scroll in between those but only show one at a time. How do I scroll to a different place within my parent div to see a different kid?

My CSS:

#parent { 
    width:500px; 
    height:600px; 
    overflow: hidden; 
}

.kids {     
    display: inline-block; 
    width:500px; 
    height:600px;    
}

Sorry for the somewhat LQ question but I'm just stumped.

like image 583
George Avatar asked Nov 13 '13 02:11

George


People also ask

How do I scroll with overflow hidden?

Use overflow: hidden instead. Use overflow-x : scroll and overflow-y : hidden , or overflow: scroll hidden instead. Use overflow-x : hidden and overflow-y : scroll , or overflow: hidden scroll instead. Use overflow: clip instead.

Does overflow hidden prevent scrolling?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.

How do I scroll content inside a div?

To fit all the text inside the div, the bi-directional scrolling method will be used. You can apply it by placing the overflow:scroll and white-space:nowrap in the id lifestyle inside the style tag. Notice the scroll bar at the bottom and right side of the div .

How can I hide the overflowing content?

Set the div with a width or height, (otherwise it won't know whether something is overflowing). Then, add the overflow:hidden; CSS property-value pair.


1 Answers

Here is a solution using the ScrollTo() jQuery plugin.

jsFiddle example... and another example using overflow:hidden, (scrollbar hidden).

(click the parent element to scroll in the example...)

Obviously something similar could have been created without the plugin, but if you wanted the actual scroll feature, I thought it would be easiest just to use it.

jQuery

var clicks = 300;
$('#parent').click(function(){
    $('#parent').scrollTo(clicks);
    clicks += 300;
    if(clicks>1200){
        clicks=0;
    }
});

HTML

<div id="parent">
    <div class="child" id="c1">1</div>
    <div class="child" id="c2">2</div>
    <div class="child" id="c3">3</div>
    <div class="child" id="c4">4</div>
    <div class="child" id="c5">5</div>
</div>

CSS

#parent { 
    width:200px; 
    height:300px; 
    overflow-x:hidden;
    overflow-y:auto;
    background:yellow;
}
#parent:hover {
    cursor:pointer;
}

.child {     
    width:200px; 
    height:300px;
    font-size:100px;
    text-align:center;
    line-height:300px;
    color:white;
}
like image 128
Josh Crozier Avatar answered Sep 22 '22 01:09

Josh Crozier