jQuery Date picker not moving with page scroll

前端 未结 5 1103
陌清茗
陌清茗 2020-12-06 11:24

I am using the standard jQuery UI datepicker ,However when i scroll the page the date picker remains fixed . Any ideas how to solve this ?

http://jsfiddle.net/jbK6a/

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 11:40

    Couldn't find any answers on this using Bootstrap and datepicker that was having an issue with the datepicker staying attached to the element when scrolling on a modal. This was my solution:

     var dateModals = (function() {
        'use strict';
    
        var currentInput = '';
    
        var setPos = function() {
            if (currentInput === '') return false;
            var $datepicker = $('.datepicker');
            var topPos = currentInput.offset().top + currentInput.outerHeight();
            if ($datepicker.hasClass('datepicker-orient-bottom')) {
                topPos -= $datepicker.outerHeight() + currentInput.parent('.date').outerHeight();
            }
            $datepicker.css('top', topPos);
        };
    
        var attachEvents = () => {
            $('.modal').on('scroll', function() {
                setPos();
            });
    
            $('.modal').on('click', '.date input.form-control', function() {
                currentInput = $(this);
            });
        };
    
        var initialize = (function() {
            attachEvents();
        })();
    
    })();
    

    If following Bootstrap & Datepicker syntax, this should play nicely.

提交回复
热议问题