简体   繁体   English

手机上的jQuery页面淡入问题

[英]jQuery page fadein issue on mobile

I'm having a problem with a website I'm working on displaying correctly on the stock browser on Android. 我正在努力在Android的股票浏览器上正确显示网站的网站出现问题。 I know that the stock browser isn't as reliable as Chrome, however I need to get it working on the browser as the client insists on this as well as the fade in. 我知道普通浏览器不如Chrome可靠,但是我需要让它在浏览器上正常工作,因为客户坚持要求这种功能以及淡入淡出。

The issue occurs on mobile when pressing the Menu at the top. 按顶部的菜单时,此问题会在移动设备上发生。 What should happen is the page should fade out and then the menu page fades in. The problem occurs with the fade in not working and the page appearing as a black page even though the links are still use-able. 应该发生的情况是页面应该淡出,然后菜单页面淡入。问题是淡入不起作用,即使链接仍然可用,页面也会显示为黑色页面。

I've done some testing and have found that by changing the jQuery from: 我已经进行了一些测试,并通过将jQuery从以下位置更改来发现了这一点:

jQuery(document).ready(function(){

to

$(window).load(function(){

solves the issue, however this doesn't look very nice at all as all the page elements finish loading and display and then the fade in happens. 解决了这个问题,但是,由于所有页面元素都完成了加载和显示,然后发生了淡入淡出的效果,所以看起来一点也不好。 So this isn't a solution, but suggests that the stock browser is launching the fadein before the page has finished loading. 因此,这不是解决方案,而是建议普通浏览器在页面加载完成之前启动渐变。

I've also tried moving the .js file from the head in the header.php to the bottom after the Menu html. 我还尝试将.js文件从header.php的头部移至Menu html之后的底部。 This again results in the menu html loading and appearing and then the Javascript runs and fades in the menu. 这再次导致菜单html加载并出现,然后Javascript在菜单中运行并消失。 Again not optimal as it doesn't look very good. 再次不是最佳,因为它看起来不太好。

Here's the Javascript affecting it: 这是影响它的Javascript:

function transitionPage(){
    $('body').css('opacity', '0').fadeTo(1500, 1,'swing'); 

    $('.menu_open').css('opacity', '0').fadeTo(1500, 1,'swing'); 

    $('a.transition').click(function(event){
        event.preventDefault();
        linkLocation = this.href;
        $('body').css({zIndex:99}).fadeOut(3000, redirectPage);

        $('.menu_open').css({zIndex:99}).fadeOut(4000);
    });

    function redirectPage() {
        window.location = linkLocation;
    }
}

Any help would be gratefully appreciated! 任何帮助将不胜感激!

Start the page already opacity 0 then use jQuery to change it on document ready. 启动已经opacity 0的页面opacity 0然后在准备好文档时使用jQuery对其进行更改。 I used CSS3 transitions as it is simpler but it could also be done with jQuery and the display: none property. 我使用CSS3过渡是因为它更简单,但是也可以使用jQuery和display: none属性来完成。

// CSS
body {
  opacity: 0;
  transition: opacity 1.5s;
}

// JS
$(function() {
  $('body').css({opacity: 100});
});

http://jsbin.com/qecaha/1/edit http://jsbin.com/qecaha/1/edit

// CSS
body {
  display: hidden;
}

// JS
$(function() {
  $('body').fadeIn(1500);
});

http://jsbin.com/qecaha/2/edit http://jsbin.com/qecaha/2/edit

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

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