Problems with Mobiscroll - orientationchange and access address bar crashes some mobile browsers

后端 未结 1 1127
甜味超标
甜味超标 2020-12-20 08:31

Original Title but too long for post: \"ASP.NET MVC 4, Razor, JQuery, JQueryMobile, Problems with Mobiscroll - orientationchange and access address bar crashes some mobile b

1条回答
  •  时光取名叫无心
    2020-12-20 08:47

    It turns out the problem was that the older Android phones do not like the resize event the way it was written above.... and newer phones did not like the orientationchange event. The code at this link made everything work perfectly:

    http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/

    And here is how I used it:

    //
    // usage:
    //$(window).smartresize(function () {
    //    // code that takes it easy...
    //});
    //http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
    (function ($, sr) {
    
        // debouncing function from John Hann
        // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
        var debounce = function (func, threshold, execAsap) {
            var timeout;
    
            return function debounced() {
                var obj = this, args = arguments;
                function delayed() {
                    if (!execAsap)
                        func.apply(obj, args);
                    timeout = null;
                };
    
                if (timeout)
                    clearTimeout(timeout);
                else if (execAsap)
                    func.apply(obj, args);
    
                timeout = setTimeout(delayed, threshold || 100);
            };
        }
        // smartresize 
        jQuery.fn[sr] = function (fn, threshold, execAsap) { return fn ? this.bind('resize', debounce(fn, threshold, execAsap)) : this.trigger(sr); };
    
    })(jQuery, 'smartresize');
    
    
      $(function () {
            createDatePicker('date_1');
    
             $(window).smartresize(function () {
                    setDatePickerWidthAndHeight();
                }, 200);
        });
    

    I found the link in the answer of this post: window.resize in jquery firing multiple times

    Thanks!

    0 讨论(0)
提交回复
热议问题