Bootstrap DateRangePicker
Scrolling and closing the daterangepicker
by norcaljohnny
HTML
<script src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css">
<script src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css">
<section class="col-md-4"> <!-- Selecionar Datas-->
<div class="form-group has-feedback has-feedback-right">
<input type="hidden" id="dt_inicio_afastamento">
<input type="hidden" id="dt_fim_afastamento">
<label class="control-label">Just some date and time here</label>
<i class="form-control-feedback glyphicon glyphicon-calendar"></i>
<input id="escolhe_data" name="escolhe_data" class="input-mini form-control" type="text">
</div>
</section>
JavaScript
$(function() {
$('input[name="escolhe_data"]').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
locale: {
format: 'MM/DD/YYYY h:mm A'
},
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
});
$(window).scroll(function() {
if ($('input[name="daterange"]').length) {
$('input[name="daterange"]').daterangepicker("close");
}
});
});