【问题标题】:CSS opacity not working in PhonegapCSS不透明度在Phonegap中不起作用
【发布时间】:2013-04-25 17:33:30
【问题描述】:

我在电话间隙应用程序中使用 jQuery 禁用了一个按钮。 href 已删除但按钮的不透明度不起作用,因此它看起来像一个损坏的按钮。有人可以让我知道一个更好的方法来解决这个问题,或者一个更好的方法来完成这项工作。先感谢您!

这是我的代码:

jQuery.each(rolesArray, function() {
    if (this == "USER") {
        $('#disable-button').css( 'opacity', '.5');
        $('#disable-button').removeAttr('href');
    }

});

这是 HTML:

<div class="ui-block-b">
      <a href="#search" data-role="button" data-transition="flip" id="disable-button"><img src="images/logo.png" alt="Search" /></a>
    </div>

【问题讨论】:

    标签: jquery css cordova opacity


    【解决方案1】:

    我在显示带有动画的蒙版时遇到了类似的问题:

    opacity = $(maskDiv).css('opacity'); //read the opacity from CSS file
    $(maskDiv).css('opacity', 0).animate({opacity: opacity}, 500); //animate fading
    

    但是虽然这在浏览器中有效,但方法 css() 在 PhoneGap 中返回错误值并且屏幕变得完全空白(遮罩不透明度 = 1)。 所以我只是通过将不透明度值硬编码到 JS 中来解决这个问题:

    $(maskDiv).css('opacity', 0).animate({opacity: 0.5}, 500);
    

    【讨论】:

    • 虽然我的问题有点不同(phonegap 3.4 应用程序,在 Android 4.3 上测试),但此解决方案有效。我曾经使用 jquery 中转库,因此必须将 $('.double-tap-vote-image').transition({ opacity: 0 }, 1500, 'ease'); 更改为 $('.double-tap-vote-image').animate({ opacity: 0 }, 1500); 才能在我的应用程序上运行。
    【解决方案2】:
    jQuery.each(rolesArray, function() {
        if (this == "USER") {
            $("#yourButton").addClass('ui-disabled');
        }
    
    });
    

    【讨论】:

    • 好的,我在 iOS 和 Android PhoneGap 中也试过这个,但仍然没有设置不透明度。不过,它确实可以在网络浏览器中使用。
    【解决方案3】:

    我认为您要将不透明度设置为0.5的是“img”标签,而不是锚点。

    jQuery.each(rolesArray, function() { 
        if (this == "USER") { 
            $('#disable-button').removeAttr('href').find('img').css('opacity', '.5'); 
        }     
    }); 
    

    【讨论】:

    猜你喜欢
    • 2014-06-23
    • 2011-02-26
    • 2011-07-28
    • 2012-09-04
    • 2018-08-01
    • 2012-11-09
    • 2016-12-08
    • 2010-12-29
    • 2013-02-04
    相关资源
    最近更新 更多