nrzmalik

Articulate Storyline Prompt Users to Rotate Screen

May 6th, 2026
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.94 KB | Source Code | 0 0
  1. var IMAGE_URL  = 'https://cdn-icons-png.flaticon.com/512/7214/7214065.png';
  2. var LABEL_TEXT = 'Rotate Your Screen';
  3. var OVERLAY_ID = 'sl-rotate-overlay';
  4.  
  5. function createOverlay() {
  6.   if (document.getElementById(OVERLAY_ID)) return;
  7.  
  8.   var style = document.createElement('style');
  9.   style.innerHTML =
  10.     '@keyframes sl-spin {' +
  11.       '0%  { transform: rotate(0deg);  }' +
  12.       '50% { transform: rotate(90deg); }' +
  13.       '100%{ transform: rotate(90deg); }' +
  14.     '}' +
  15.     '@keyframes sl-pulse {' +
  16.       '0%,100%{ opacity:1;   }' +
  17.       '50%    { opacity:0.5; }' +
  18.     '}';
  19.   document.head.appendChild(style);
  20.  
  21.   var overlay = document.createElement('div');
  22.   overlay.id = OVERLAY_ID;
  23.   overlay.style.cssText =
  24.     'position:fixed;top:0;left:0;width:100%;height:100%;' +
  25.     'z-index:99999;display:flex;flex-direction:column;' +
  26.     'align-items:center;justify-content:center;gap:24px;' +
  27.     'background:rgba(10,10,20,0.92);' +
  28.     'backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);';
  29.  
  30.   var img = document.createElement('img');
  31.   img.src = IMAGE_URL;
  32.   img.alt = LABEL_TEXT;
  33.   img.style.cssText =
  34.     'width:110px;height:auto;' +
  35.     'animation:sl-spin 2s ease-in-out infinite;' +
  36.     'transform-origin:center;' +
  37.     'filter:drop-shadow(0 0 16px rgba(255,255,255,0.3));';
  38.  
  39.   var label = document.createElement('p');
  40.   label.textContent = LABEL_TEXT;
  41.   label.style.cssText =
  42.     'margin:0;color:#fff;' +
  43.     'font-size:22px;font-weight:700;letter-spacing:0.05em;' +
  44.     'font-family:system-ui,sans-serif;text-align:center;' +
  45.     'animation:sl-pulse 2s ease-in-out infinite;';
  46.  
  47.   overlay.appendChild(img);
  48.   overlay.appendChild(label);
  49.   document.body.appendChild(overlay);
  50. }
  51.  
  52. function checkOrientation() {
  53.   var overlay = document.getElementById(OVERLAY_ID);
  54.   var isMobile = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0);
  55.  
  56.   if (!isMobile) {
  57.     if (overlay) overlay.style.display = 'none';
  58.     return;
  59.   }
  60.  
  61.   var isPortrait;
  62.   if (window.screen && window.screen.orientation && window.screen.orientation.type) {
  63.     isPortrait = window.screen.orientation.type.indexOf('portrait') !== -1;
  64.   } else if (typeof window.orientation !== 'undefined') {
  65.     isPortrait = (window.orientation === 0 || window.orientation === 180);
  66.   } else {
  67.     isPortrait = window.innerHeight > window.innerWidth;
  68.   }
  69.  
  70.   if (isPortrait) {
  71.     createOverlay();
  72.     document.getElementById(OVERLAY_ID).style.display = 'flex';
  73.   } else {
  74.     if (overlay) overlay.style.display = 'none';
  75.   }
  76. }
  77.  
  78. // Attach listeners only once
  79. if (!window._slRotateListenerAdded) {
  80.   window.addEventListener('orientationchange', checkOrientation);
  81.   window.addEventListener('resize', checkOrientation);
  82.   if (window.screen && window.screen.orientation) {
  83.     window.screen.orientation.addEventListener('change', checkOrientation);
  84.   }
  85.   window._slRotateListenerAdded = true;
  86. }
  87.  
  88. // Run immediately on trigger fire
  89. checkOrientation();
Advertisement
Add Comment
Please, Sign In to add comment