gpt4 book ai didi

加载时的 Javascript 全屏图像,2 秒后消失(空闲时间后的屏幕保护程序)

转载 作者:可可西里 更新时间:2023-11-01 13:21:18 24 4
gpt4 key购买 nike

我想结合在我的 Shopify 正面网站上全屏显示图片(我们的 Logo )的功能,并使其在几秒钟后自动淡出或消失,以便人们可以在图像或我们的 Logo 消失后访问该网站(2秒)。

现在我有了 HTML 的这两部分,但不知何故它们无法协同工作。

有人可以帮忙吗?

谢谢

<div id="makethisvanish"><img src="image"></div> 

<div class="fixed-background">
<img src="image" class="myimg">
</div>



<script type="text/javascript">
window.onload = function () {
window.setTimeout( vanishText, 2000 ); // 2000 is 2 seconds
}
function vanishText() {
document.getElementById( 'makethisvanish' ).style.visibility = 'hidden';
}
</script>


<style>
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}

.fixed-background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden;
}

.myimg {
height: inherit;
}
</style>

最佳答案

试试下面的代码:

<head>
<script>
window.onload = function () {
window.setTimeout(vanishText,2000); // 2000 is 2 seconds
}
function vanishText() {
document.getElementById('makethisvanish').style.opacity = '0';
}
</script>

<style>
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}

#makethisvanish {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
min-height: 100%;
height: auto;
opacity: 1;
z-index:1000;
margin: 0 auto;
transition: opacity .5s linear;
}

#makethisvanish img {
width: 100%;
height: auto;
}

.fixed-background {
position: relative;
top: 0;
left: 0;
height: 100%;
overflow: hidden;
}

.grid__item {
height: 50px;
}

.myimg {
height: 100%;
width: auto;
}
</style>
</head>
<body>

<div id="makethisvanish">
<img src="http://i65.tinypic.com/5nn1va.jpg">
</div>

<div class="grid__item">
<div class="fixed-background">
<img src="http://i65.tinypic.com/5nn1va.jpg" class="myimg">
</div>
</div>
</body>

我相信这应该做什么?

如有问题请反馈。我会尽力帮助您解决问题;)

编辑

对于全屏图片,你需要的更少:

<head>
<script>
window.onload = function () {
window.setTimeout(vanishText,2000); // 2000 is 2 seconds
}
function vanishText() {
document.getElementById('makethisvanish').style.opacity = '0';
}
</script>

<style>

#makethisvanish {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
min-height: 100%;
height: auto;
opacity: 1;
z-index:1000;
margin: 0 auto;
transition: opacity .5s linear;
}

#makethisvanish img {
width: 100%;
height: auto;
}

</style>
</head>
<body>

<div id="makethisvanish">
<img src="http://i65.tinypic.com/5nn1va.jpg">
</div>

</body>

也许您需要在 vanishText() 中添加另一行:

document.getElementById('makethisvanish').style.zIndex = "0";

但请先尝试上面的代码。

EDIT_2

用以下内容替换头部的脚本:

window.onload = function () {
window.setTimeout(vanishText,2000); // 2000 is 2 seconds
}

var IDLE_TIMEOUT = 60; //seconds
var _idleSecondsCounter = 0;

window.setInterval(CheckIdleTime, 1000);

function CheckIdleTime() {
_idleSecondsCounter++;
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
screensaver();
}
}

function vanishText() {
document.getElementById('makethisvanish').style.opacity = '0';
document.getElementById('makethisvanish').style.zIndex = '-1';
}

function screensaver() {
document.getElementById('makethisvanish').style.zIndex = "1000";
document.getElementById('makethisvanish').style.opacity = "1";
}


function resetTimer() {
if(_idleSecondsCounter >= IDLE_TIMEOUT) {
vanishText();
}
_idleSecondsCounter = 0;
}

document.onclick = function() {
resetTimer();
};

document.onmousemove = function() {
resetTimer();
};

document.onkeypress = function() {
resetTimer();
};

您可能必须调整 IDLE_TIMEOUT。测试时设置为 5 秒。我可能会将其设置为一分钟,也许更长一点。如果移动鼠标、完成鼠标单击或按下键盘上的某个键,“屏幕保护程序”应该会消失。

关于加载时的 Javascript 全屏图像,2 秒后消失(空闲时间后的屏幕保护程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47554676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com