Soy nuevo en la programación y el siguiente código lo obtuve a través de un proyecto de código abierto.
Estoy cargando un widget en un sitio web. Entonces, en lugar de cargar inmediatamente el widget, quiero que tarde 10 segundos antes de mostrar el widget.
Así es como estoy cargando el widget.
Todo el código a continuación............
switch (methodName) { case 'init': const loadedObject = Object.assign(defaultConfig, item[1]); // the actual rendering of the widget const wrappingElement = loadedObject.element ?? win.document.body; targetElement = wrappingElement.appendChild( win.document.createElement('div') ); targetElement.setAttribute('id', `widget-${instanceName}`); render(targetElement, loadedObject); // store indication that widget instance was initialized win[`loaded-${instanceName}`] = true; break; default: console.warn(`Unsupported method [${methodName}]`, item[1]); } }debe usar la función setTimeout como tal:
switch (methodName) { case 'init': const loadedObject = Object.assign(defaultConfig, item[1]); setTimeout(function(){ // the actual rendering of the widget const wrappingElement = loadedObject.element ?? win.document.body; targetElement = wrappingElement.appendChild( win.document.createElement('div') ); targetElement.setAttribute('id', `widget-${instanceName}`); render(targetElement, loadedObject); // store indication that widget instance was initialized win[`loaded-${instanceName}`] = true; }, 10000); break; default: console.warn(`Unsupported method [${methodName}]`, item[1]); } }como se muestra en esta respuesta aquí