在 jquery 移动列表中使用自定义图标
我找到了有关使用 jQuery mobile 按钮 的自定义图标的文档如何使用现有图标自定义列表,但我无法找到如何将自定义图标添加到列表视图(即我自己创建的PNG)。
我尝试将 data-url
: 设置
<li data-icon="action-arrow">...</li>
为 png 文件的名称,如 jQuery 移动按钮 但这不起作用。
I have found documentation on using custom icons for jQuery mobile buttons and how to customize lists using existing icons but I am unable to find how to add custom icons to list views (i.e. PNGs I have created my self).
I have tried setting the data-url
:
<li data-icon="action-arrow">...</li>
to the name of the png file as explained in the jQuery mobile buttons but this doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为新图标添加 CSS 规则:
更新:
您还可以使 CSS 规则比 jQuery Mobile 规则更具体,如下所示:
就是这样,然后您应该能够通过像这样引用它来使用该图标:
请注意,如果
li
元素中没有链接,则不会显示图标。这是一个演示: http://jsfiddle.net/KYaQT/106/ (更新的链接)
You need to add a CSS rule for your new icon:
Upadate:
You can also just make your CSS rule more specific than the jQuery Mobile rule like so:
That's about it, you should then be able to use this icon by referencing it like this:
Note that the icon does not display if there is not a link in the
li
element.Here is a demo: http://jsfiddle.net/KYaQT/106/ (Updated Link)
除了背景图像之外,您可能还需要修改背景颜色和图标容器的大小。默认情况下,图标为 18x18 像素。如果您的图标大于该图标,您还必须更改位置和边距。
In addition to the background-image you may want to modify the background-color and the size of the icon container. By default the icon is 18x18 pixels. If your icon is larger than that you will have to change the position and margins as well.
我已经通过这种方式解决了,因为我想为我的网络应用程序使用 svg 文件:
.newlist span.ui-icon{display:none}
style{position:relative}
style{position:absolute;width:24px;heigh;24px;right:10px;top:50%;margin-top:- 12px;display:block}
元素内的
元素之后
将带有图像的 div 放在我使用的 24x24 像素图像
I've solved this way, since I wanted to use svg files for my web app:
.newlist span.ui-icon{display:none}
style{position:relative}
style{ position:absolute;width:24px;heigh;24px;right:10px;top:50%;margin-top:-12px;display:block}
<a>
element inside the<li>
elementi used 24x24 pixels images