Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Overflow: hidden with absolute positioning (jQuery)

Featured Replies

Hi everyone,

 

I've got sort of a strange problem. I'm trying to make a 300px width window (.container with overflow: hidden;), which shows the selected colored block. Whenever a link inside a colored block is clicked, the anchor should slide a colored block, which is outside the container because of absolute positioning inside the .container.

 

When overflow:hidden is turned off, everything seems to be working good. But whenever it is turned on, the positions of the absolute blocks seem to be going all crazy?

 

With the code it all should become a little be more clear. An example an be found at: http://abovetherim.nl/slide.html (this is WITH overflow: hidden).

 

Javascript (jQuery)

<script type="text/javascript">
$(document).ready(function(){	

$('.title').click(function(){

	var targetClick = $(this).attr('href');
	var curEl = $(this).parent();	

if ($(targetClick).css('left') === '0px') {
   	$(curEl).animate({left: '300px'}, 'slow');

   	$(targetClick).animate({left: '0px'}, 'slow');
	}

if ($(targetClick).css('left') === '300px') {		
	$(curEl).animate({left: '-300px'}, 'slow');

	$(targetClick).animate({left: '0px'}, 'slow');
   		}

if ($(targetClick).css('left') === '-300px') {
	$(curEl).animate({left: '300px'}, 'slow');

	$(targetClick).animate({left: '0px'}, 'slow');
		}

}); //end click
}); //end script
</script>

 

CSS

.container{
position: relative; 
width: 300px; 
height: 300px; 
margin: 0 auto; 
overflow: hidden;
}
.screen{
	position: absolute; 
	left:0; 
	top:0; 
	width: 300px; 
	height: 300px; 
	z-index: 0;
	}
	.green{background: green;}
	.red{background: red;}
	.yellow{background: yellow;}

 

HTML

<div class="container">
<article class="screen red" id="red">
	<a href="#green" class="title">become green!</a>
</article>

<article class="screen yellow" id="yellow">
	<a href="#red" class="title">become red!</a>
</article>

<article class="screen green" id="green">
	<a href="#yellow" class="title">become yellow!</a>
</article>
</div>

 

So why doesn't this work. I am obviously doing something wrong?

Edited by SamP

  • Author

He guys,

 

I just figured it out. All I had to do was add:

 

e.preventDefault();

 

Still don't understand exactly why it was going all crazy?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.