I have a container with a list inside. The list items can be dragged, moving with the mouse.
The container is scrollable with:
overflow-y: scroll;
By setting this property, Chrome automatically sets the overflow-x
property to 'auto'. If I set overflow-x: visible
it is ignored by Chrome. If I set overflow-x: hidden
then obviously the item is cropped.
When I drag a list item outside of the left or top edge of the container, it is cropped to the edges of the container. If I drag it out of the right or bottom edges the container scrolls to accommodate it. I would like the item to be able to dragged outside of the container without it being cropped and without it triggering scroll.
Given that the container must be set to overflow-y: scroll
and that this in turn forces Chrome to set overflow-x: auto
, is there any way I can achieve this or is it impossible?
Codepen: http://codepen.io/Pedr/pen/azLWeY
Note: I know I can hack this by using padding to offset the container (so that the limits of the container actually end beyond its visual edges), but that is not an option in my situation.
$(function() {
$('.Wrapper').mousemove(function(event){
$('.Item').offset({left: event.pageX, top: event.pageY});
});
})
html,
body {
height: 100%;
}
.Wrapper {
width: 100%;
height: 100%;
position: absolute;
}
.Container {
background: grey;
position: absolute;
width: 50%;
left: 25%;
min-height: 100%;
overflow-y: scroll;
overflow-x: hidden; // Clips Item
// If left at auto it will clip the item on the top and left edge and scroll if the item overlaps the bottom or right edge.
}
.Item {
padding: 20px;
background: red;
position: absolute;
width: 600px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Wrapper">
<div class="Container">
<div class="Item">ITEM</div>
</div>
</div>