【发布时间】:2017-05-19 12:15:12
【问题描述】:
我正在使用jscolor colorpicker,它只能附加到按钮元素或输入元素。我想将它用于div。我尝试过这种方式-
https://jsfiddle.net/anuranpal/Lead7c7q/43/
CSS
edit-color-container {
border: 1px solid gainsboro;
height: 70px;
width: 70px;
text-align: center;
}
.select-button {
background: none!important;
border: none;
padding: 0!important;
cursor: pointer;
display: block;
width: 100%;
height: 100%;
-moz-user-select: none;
-webkit-user-select: none;
/* this will work for QtWebKit in future */
-webkit-user-drag: none;
}
.selected-color-container {
-moz-border-radius: 50px/50px;
-webkit-border-radius: 50px 50px;
border-radius: 50px/50px;
width: 35px;
height: 35px;
background: #DF068C;
display: inline-block;
vertical-align: top;
margin: auto;
margin-top: 5px;
position: relative;
}
HTML
<div class="edit-color-container">
<input id="selected-color-value" type="hidden" value="#DF068C" />
<button id="editColor" class="select-button jscolor " data-jscolor="
{width:150, height:150,valueElement:'selected-color-
value',styleElement:'selectedColor',borderWidth:0,borderColor:'#FFF',
insetWidth:0, insetColor:'#FFF',shadow:false,
backgroundColor:'#e6e7e9',borderRadius:2, zIndex:'2000'}">
<div class="selected-color-container" id="selectedColor"></div>
<div class="uk-text-small uk-text-primary uk-margin-small-top" style="margin:auto">Edit</div>
</button>
</div>
但是在这里我使用了按钮而不是 div,它会在 chrome 中产生一些问题,比如如果我点击圆圈,什么都不会发生,但是如果我在圆圈外点击,颜色选择器会切换。
所以,我想使用 div 而不是按钮,并在单击 div 时打开colorpicker。
请帮忙。提前谢谢你:-)
【问题讨论】:
-
使用
input代替 div 并使用readonly属性没有帮助?
标签: javascript google-chrome button jscolor