Code Monkey home page Code Monkey logo

Comments (3)

gaearon avatar gaearon commented on May 20, 2024

FWIW this works well for me:

'use strict';

var viewportUnitsBuggyfill = require('viewport-units-buggyfill'),
    { any } = require('underscore');

viewportUnitsBuggyfill.init();
var patchedViewportStyleNode = document.getElementById('patched-viewport');

function isAppStyleNode(node) {
  return node.tagName === 'STYLE' && node !== patchedViewportStyleNode;
}

function refreshViewportBuggyfill() {
  viewportUnitsBuggyfill.refresh();
  patchedViewportStyleNode.parentNode.appendChild(patchedViewportStyleNode);
}

function handleHeadMutation(mutationRecords) {
  if (any(mutationRecords, record => any(record.addedNodes, isAppStyleNode))) {
    refreshViewportBuggyfill();
  }
}

if (patchedViewportStyleNode) {
  if (typeof MutationObserver !== 'undefined') {
    new MutationObserver(handleHeadMutation).observe(document.head, {
      childList: true
    });
  } else {
    setInterval(refreshViewportBuggyfill, 1500);
  }
}

This is probably rather unusual request so closing this.

from style-loader.

seanemmer avatar seanemmer commented on May 20, 2024

Thanks for posting this. I'm attempting to run Viewport Units Buggyfill as part of a similar Webpack build and am unable to successfully apply the viewport units to my targeted DOM elements.

Had a couple of follow up questions:

  1. What is the 'patched viewport' referenced here? Do I need to re-run this script for each DOM element I am applying CSS viewport properties to (in certain views there are multiple nested elements)?

  2. My app is structured as an SPA. Do I need to wait until the target DOM elements are rendered to execute the script above, or can I execute the script once when the application initializes.

from style-loader.

gaearon avatar gaearon commented on May 20, 2024

Sorry, I don't remember anything about this πŸ˜”

from style-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.