I'm trying to replicate a carousel type layout with fieldsets. To break down the form into more user friendly chunks, I want to show a fieldset with 12 fields at once, and there are 6 fieldsets. These are only checkboxes so it's not as bad as it sounds!
I've got everything working in terms of the scroll backwards and forwards, but if a click to move the position has taken place, then the window is resized, it layout breaks - you start to see different fieldsets that should not be visible - presumably due to the now incorrect position set by the JS now that the browser width has changed.
I appreciate there may well be a much better way of doing this. However, I wanted to have a slide effect where, because the whole div is moving, the fieldset sliding in happens exactly as the other slides out.
Unfortunately JSFiddle is not working due to viewport width (vw) css. Let me know if there is a way around this.
See screenshots below - first one is before clicking 'Next' to move position, second one is after clicking next and then resizing browser. Note, you can resize the browser before clicking 'Next', and it still works fine when you then do click 'Next', it's just resizing after clicking that's causing the problem in the 2nd screenshot.
HTML
<div id="fieldset-container">
<fieldset>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
</fieldset>
<fieldset>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
<div class="field">
<div class="checkbox">
<label data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<?php echo ($field['definition']); ?>">
<input type="checkbox" name="<?php echo ($field['name']); ?>" value="<?php echo ($field['title']); ?>"> <?php echo ($field['title']); ?>
</label>
</div>
</div>
</fieldset>
<button class="fieldset-next">Next</button>
<button class="fieldset-previous">Previous</button>
</div><!--/#fieldset-container-->
CSS
#fieldset-container {
width: 600vw;
overflow: hidden;
white-space: nowrap;
margin-right: 100vw;
position: relative;
}
#fieldset-container fieldset {
display: inline-block;
overflow: hidden;
width: 100vw;
margin: 0 auto;
padding: 0 100px;
}
JS
$('.fieldset-next').click(function(e) {
e.preventDefault();
var right = parseInt($('#fieldset-container').css("right")) + parseInt($('#fieldset-container fieldset').outerWidth());
$('#fieldset-container').animate({
right: right
}, 1000)
});
$('.fieldset-previous').click(function(e) {
e.preventDefault();
var right = parseInt($('#fieldset-container').css("right")) - $( window ).width();
$('#fieldset-container').animate({
right: right
}, 1000)
});