每次我最大化或最小化、按 ctrl - 或 + javascript 中的屏幕时,超链接都会跟随其位置/位置

问题描述 投票:0回答:1

每次最大化或最小化、按 ctrl - 或 + 屏幕时,如何使超链接跟随其位置/位置?例如:如果我按 ctrl - 或 +,超链接将遵循设置的坐标,并且当它变大时不会停留或阻止其他按钮和超链接。

问题很复杂,但我希望我可以制作一个视频来澄清。我从 https://www.w3schools.com/jsref/prop_style_position.asp 遵循了这个样式位置属性,但只有固定值才是使超链接出现的值,而且位置似乎只是停留在它的坐标上。

期待任何人的善意帮助。提前非常感谢您。

// ==UserScript==
// @name         Launch a Web Page
// @namespace    http://your-website.com
// @version      1.0
// @description  Will launch a WebPage
// @author       me
// @match        https://example.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_openInTab
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
'use strict';

// Function to launch the webpage
function launchWebpage() {
    // Adjust the URL to the webpage you want to launch
    const targetURL = 'https://example.com/';
    window.open(targetURL, '_blank');
}

// Create a hyperlink positioned on the upper middle of the screen
const launchLink = document.createElement('a');
launchLink.href = 'javascript:void(0)';
launchLink.textContent = 'WebPage';
launchLink.style.position = 'fixed';
launchLink.style.top = '10px';
launchLink.style.right = '30%';
launchLink.style.transform = 'translateX(-50%)';
launchLink.style.color = 'white';
launchLink.style.padding = '10px';
launchLink.style.borderRadius = '5px';
launchLink.style.textDecoration = 'none';
launchLink.style.fontSize='18px';
document.body.appendChild(launchLink);

// Add event listener to the hyperlink
launchLink.addEventListener('click', launchWebpage);

})();
javascript hyperlink
1个回答
0
投票

我认为'position:fixed'样式在Document中很有用,但是最大化或最小化是由浏览器控制的,它们是不同的级别。

© www.soinside.com 2019 - 2024. All rights reserved.