0

I am trying to trigger an event in a web browser on a desktop

$(window).trigger('resize');

The issue is on mobile it doesn't seem to be triggering. Is there an alternative method for mobile?

I am using tablesaw plugin for grids. When the screen is small in size, the columns will not fit and as such a swipe will be provided to move between them. When I sort them, all the columns gets squeezed and shown on the small screen, but after I trigger the resize event, an event in the plugin will get called that will fix them. On the mobile, this event doesn't exist I guess and I'm not targeting the orientation.

Mohamad Yassine
  • 62
  • 2
  • 11

2 Answers2

2

a variation of this (JavaScript/JQuery: $(window).resize how to fire AFTER the resize is completed?)

this will run on resize and orientchange.

var waitForFinalEvent=function(){var b={};return function(c,d,a){a||(a="THISPAGE");b[a]&&clearTimeout(b[a]);b[a]=setTimeout(c,d)}}();
var fullDateString = new Date();

$(document).ready(function(){

   $.resized = function(){

    waitForFinalEvent(function(){
        //function to run

       }, 300, fullDateString.getTime())
    }

    window.addEventListener("orientationchange", function() {
        $.resized();
    });

    $(window).resize(function () {
        $.resized();
    });

    $.resized();

    });
Community
  • 1
  • 1
imvain2
  • 15,480
  • 1
  • 16
  • 21
0
window.dispatchEvent(new Event('resize'));
  • Could you add some explanation and maybe links to docs? Just code without any explanation isn't very useful -- it may help the OP, but probably won't help future visitors. – Michał Perłakowski May 05 '16 at 19:25