小程序原生所带的weui框架做小程序UI实在太方便了,但是他的一些细微变化也是让开发中碰到不少头疼的问题
一直以来单选多选的美化都是设计师重点表达的地方之一
而weui-wxss-master中的单选多选样式又写的与众不同,不同与常规的weui添加after伪类来显示 不同,他是通过type="success_no_circle"来实现的,所以无论怎么更改icon或icon的after或befor都无效果
这里想到一个变通的方法先给icon添加一个外层容器,给该容器添加背景图片来实现在不选中状态的UI样式,再给icon添加一个背景图片,同时控制 icon的显示 隐藏来达到图标切换的效果,
这里额外说下,在小程序中,背景图片是不许直接引用项目中的图片,否则 会直接报错,
可以直接引用一个带http的绝对地址图片,或者转化成bese64来实现【图片在线转换64,https://tool.css-js.com/base64.html】
先上原始UI
<radio-group bindchange="radioChange"> <label class="weui-cell weui-check__label" wx:for="{{radioItems}}" wx:key="value"> <radio class="weui-check" value="{{item.value}}" checked="{{item.checked}}"/> <view class="weui-cell__bd">{{item.name}}</view> <view class="weui-cell__ft weui-cell__ft_in-radio" wx:if="{{item.checked}}"> <icon class="weui-icon-radio" type="success_no_circle" size="16"></icon> </view> </label> </radio-group>
改良后的UI
<radio-group bindchange="radioChange"> <label class="weui-cell weui-check__label" wx:for="{{radioItems}}" wx:key="value"> <radio class="weui-check" value="{{item.value}}" checked="{{item.checked}}"/> <view class="weui-cell__bd"> <view>{{item.name}}<text>{{item.time}}</text></view> <view class=‘text‘>{{item.text}}</view> </view> <view class="weui-cell__ft weui-cell__ft_in-radio"> <view class=‘price‘>{{item.price}}</view> <view class=‘ck‘><icon class="weui-icon-radio" type="success_no_circle-1" size="16" wx:if="{{item.checked}}"></icon></view> </view> </label> </radio-group>
data: { radioItems: [ { name: ‘标准洗‘, time:‘30分钟‘,text: ‘30分钟‘, price:‘¥5‘, value: ‘0‘, checked: true}, { name: ‘单脱洗‘, time: ‘30分钟‘, text: ‘30分钟‘, price: ‘¥5‘, value: ‘1‘ }, { name: ‘快洗‘, time: ‘30分钟‘,text: ‘30分钟‘, price: ‘¥5‘,value: ‘2‘ }, { name: ‘深层洗‘, time: ‘30分钟‘,text: ‘30分钟‘, price: ‘¥5‘, value: ‘3‘ }, ] }
.weui-cell__ft .ck{ width: 20px; height: 20px; padding: 0; padding-top: -3px; vertical-align: middle; display: inline-block; background-size: 100% auto; background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMDY3IDc5LjE1Nzc0NywgMjAxNS8wMy8zMC0yMzo0MDo0MiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTUgKFdpbmRvd3MpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjc5REQ0Q0FFNkFDQjExRTg4NUIxRjRFODhCN0JBODAxIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjc5REQ0Q0FGNkFDQjExRTg4NUIxRjRFODhCN0JBODAxIj4gPHh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Rp+f1kdc1T0bjneLPN0h5ahWzrgfQcYPNXUmzb8uVKEjrLGZY7dyGr+CXlPnsN7ue2pJ1BVAzGuxcMxTypHIdB7MFnxx2L6tVMU/BDbkuX0NaYxKjTmW7Ut+e9QxVfpnwVFwH3xVafhER7appNKBh80mtVLatfHXavvaZHJoogcW+TNEhxZXijTqYWfMSWJCiz6Xrrx+hvgjwACimajJuQXaOgAAAABJRU5ErkJggg==); } .weui-cell__ft_in-radio .weui-icon-radio{ width: 20px; height: 20px; margin: 0; padding: 0; vertical-align: top; background-size: 100% auto; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMDY3IDc5LjE1Nzc0NywgMjAxNS8wMy8zMC0yMzo0MDo0MiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTUgKFdpbmRvd3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