使用自定义图标在jQuery

使用自定义图标在jQuery

本文介绍了使用自定义图标在jQuery Mobile中创建按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在为客户开发应用程序,并试图创建一个带有完全自定义图标的按钮.图标为30px x 30px,中间是透明的.

I am working on an app for a client and am trying to create a button with a completely custom icon. The icon is 30px x 30px and transparent in the middle.

使用此CSS代码,我几乎实现了我想要的:

I have almost achieved what I want using this css code:

/* info button override */
.ui-icon-info-page {
    background: url(images/G_help_icon_round.png) 50% 50% no-repeat;
    background-size: 30px 30px;
    background-color: black;
}

但是在图标内部出现了一个黑色的细圆圈,并且图标图像似乎被切除了:

But there is a thin black circle that appears inside the icon, and also the icon image appears to be cut off:

我要删除此圆圈并防止显示图标?从被切断.另外,我希望问号是透明的,而不是黑色的,以显示下方导航栏的图像.但是,如果我尝试将背景色设置为透明,则该按钮将显示为完全白色:

I want to remove this circle and prevent the icon ? from being cut off. Also, I would like the question mark to be transparent instead of black, to show the image of the navigation bar beneath. If I try to set the background color to transparent though, the button appears entirely white:

我该怎么做?

更新:

我尝试应用此代码:

/* info button override */
.ui-icon-info-page {
    background: url(help.png) 50% 50% no-repeat;
    background-size: 30px 30px;
    width: 30px;
    height: 30px;
    margin-top: -15px !important;
    box-shadow: none;
    -webkit-box-shadow: none;
}

并得到以下结果:

我可以通过调整顶部和左侧边距来移动图标,但是在以黑色圆圈为中心的框架之外,其边缘被切掉了:

I'm able to move the icon around by adjusting the top and left margins, but it's edges are cut off outside a frame centered on the black circle:

更新2:

这是我正在使用的按钮(请注意,这里是不可见的,因为它是白色背景上的白色按钮):

Here is the button I am using (Note that it is invisible here because it is a white button on a white background):

这是我用来加载按钮的html代码:

Here is the html code that I use to load the button:

<div data-role="header" data-position="fixed">
            <div><img border="0" src="images/G_iphone_navbar_logo.png" style="display:inline;"/> </div>
            <a href="index.html" data-icon="refresh" class="ui-btn-left" data-transition="fade" data-iconpos="notext" data-theme="a"></a>
            <a href="info.html" data-icon="info-page" class="ui-btn-right" data-transition="flip" data-iconpos="notext" data-theme="a"></a>

</div>

推荐答案

这应该可以解决问题

/* info button override */
.ui-icon-info-page {
    background: url(help.png) 50% 50% no-repeat;
    background-size: 30px 30px;
    width: 30px;
    height: 30px;
    margin-top: -15px !important;
    box-shadow: none;
    -webkit-box-shadow: none;
}

请确保在jquery移动CSS之后加载应用程序CSS文件.

Please ensure you are loading your application css file after jquery mobile css.

以下是示例代码,该代码基于您已解决问题的发布的代码

Here is a sample code based on the code you posted with the issue fixed

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
        <style>
            #rightBtn .ui-btn-inner {
                width: 30px;
                height: 30px;
                margin: -3px;/*Modify to change icon position wrt the header*/
                border: none !important;
            }
            .ui-icon-custom {
                background: url(http://i.stack.imgur.com/AqicD.png) 50% 50% no-repeat;
                background-size: 30px 30px;
                width: 30px;
                height: 30px;
                box-shadow: none;
                -webkit-box-shadow: none;
                margin: 0 !important;
            }
        </style>
    </head>
    <body>
        <div data-role="header">
            <h1>Page Title</h1>
            <a href="index.html" data-icon="refresh" class="ui-btn-left" data-transition="fade" data-iconpos="notext" data-theme="a"></a>
            <a href="info.html" id="rightBtn" data-icon="custom" class="ui-btn-right" data-transition="flip" data-iconpos="notext" data-theme="a"></a>
        </div><!-- /header -->

        <div data-role="content"></div><!-- /content -->

        </div><!-- /page -->

    </body>
</html>

此处的演示- http://jsfiddle.net/LCsmt/

让我知道是否有帮助.

这篇关于使用自定义图标在jQuery Mobile中创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:48