简体   繁体   English

使用网址对页面加载的过渡效果

[英]Transition effect on page load with url

This code redirects to example-page.php: 这段代码重定向到example-page.php:

setTimeout(function() {
  window.location.href = "/example-page.php";
}, 5000);

I'm trying to add a transition effect, so when it redirects, it looks like it's scrolling left or right off the page to the other. 我正在尝试添加过渡效果,因此当它重定向时,看起来好像是在页面上向左或向右滚动到另一个。 Any help would be greatly appreciated! 任何帮助将不胜感激! I've tried using Jquery but i'm still fairly new and struggling. 我已经尝试过使用Jquery,但是我仍然很新而且很挣扎。

You could try something like this: 您可以尝试这样的事情:

var elements = document.getElementsByTagName('body');
setTimeout(function(){
 elements[0].style.opacity = 1;
    (function fade(){
        var opacloader = parseFloat(elements[0].style.opacity);

        (elements[0].style.opacity = opacloader - .1)<0.1?window.location.href='example':setTimeout(fade,40)})();
},4800);

What basically happens here is: 这里基本上发生的是:

After 4.8 seconds, the actual page's body is faded out. 4.8秒后,实际页面的正文逐渐淡出。 (You can add another effect if you want to.) When the body's oppacity of the actual page is 0, the redirect will happen. (如果需要,可以添加其他效果。)当实际页面的正文不透明度为0时,将发生重定向。

On the next page, you could do a fadeIn effect, which might come close to what you expect 在下一页上,您可以执行fadeIn效果,该效果可能接近您的预期

HERES A DEMO 在这里演示


To fade the body in on the next page, you can use this: 要在下一页上淡入主体,可以使用以下方法:

var elements = document.getElementsByTagName('body');
elements[0].style.opacity = 0;
(function fadeIn() {

        var opacity = parseFloat(elements[0].style.opacity);

        if (opacity == 1) return;

        elements[0].style.opacity = opacity + 0.1;
        setTimeout(fadeIn, 100); //<<<<<<<< here you set the speed!
    })();

DEMO FADE IN 示范淡入

 (function(){ document.body.classList.add("fadeout"); window.setTimeout(function(){ window.location.href = "http://www.newlocation.com"; },5000) })() 
 body{ transition:opacity 5000ms; opacity:1; } body.fadeout{ opacity:0; } 

You should put the transition effect in the landing page (example-page.php). 您应该将过渡效果放在登录页面(example-page.php)中。

For example, you can hide the whole body with a css rule #wrapper{display:none} , and show it sliding with jquery 例如,您可以使用css规则#wrapper{display:none}隐藏整个身体,并使用jquery滑动显示它

 $(document).ready(function () {
      $('#wrapper').slideToggle(1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM