- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个网站,您可以在其中上传图片,然后在点击图片点后,该网站将返回您点击的点的十六进制代码。
你可以点击输入框(按钮)来上传图片,但我也想在拖放图片后让它工作。
我正在使用标签使按钮看起来很漂亮。所以,我有一个隐藏输入框的脚本:
<script>
(function(e,t,n){
var r=e.querySelectorAll("html")[0];
r.className=r.className.replace(/(^|\s)no-js(\s|$)/,"$1js$2")
})
(document,window,0);
</script>
等效的 HTML 行是:
<html lang="en" class="no-js">
这是输入框和标签的 HTML 脚本:
<input type="file" name="file_upload[]" id="file_upload" class="inputfile inputfile-2" data-multiple-caption="{count} files selected" multiple />
<label for="file_upload">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg>
<span>CHOOSE A FILE</span>
</label>
如果我删除标签并取消隐藏输入框,则拖放操作正常。
片段如下:
//Script that hides the input box (label is a substitute)
(function(e,t,n){var r=e.querySelectorAll("html")[0];r.className=r.className.replace(/(^|\s)no-js(\s|$)/,"$1js$2")})(document,window,0);
//Hex picker function
var $picked = $("#picked"); // Just to preview picked colors
var canvas = $('#canvas_picker')[0];
var context = canvas.getContext('2d');
$("#file_upload").change(function (e) {
var F = this.files[0];
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(F);
});
function imageIsLoaded(e) {
var img = new Image();
img.onload = function(){
canvas.width = this.width;
canvas.height = this.height;
context.drawImage(this, 0, 0);
};
img.src = e.target.result;
}
$('#canvas_picker').click(function(event){
var x = event.pageX - $(this).offset().left;
var y = event.pageY - $(this).offset().top;
var img_data = context.getImageData(x,y , 1, 1).data;
var R = img_data[0];
var G = img_data[1];
var B = img_data[2];
var rgb = R + ',' + G + ',' + B ;
var hex = rgbToHex(R,G,B);
$('#rgb input').val( rgb );
$('#hex input').val('#' + hex);
$picked.append("<span style='background:#"+hex+"'>#"+hex+"</span>");
});
function rgbToHex(R, G, B) {
return toHex(R) + toHex(G) + toHex(B);
}
function toHex(n) {
n = parseInt(n, 10);
if (isNaN(n)) return "00";
n = Math.max(0, Math.min(n, 255));
return "0123456789ABCDEF".charAt((n - n % 16) / 16) + "0123456789ABCDEF".charAt(n % 16);
}
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/dPJ5r9gl3kK6ijoeP1IRsvY6323mHUZFJMgTvxaG2iE.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/EsvMC5un3kjyUhB9ZEPPwg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
body {
background: hsl(184,65%,49%);
font-family: 'Lato';
color: #000;
font: 15px/1.4em;
}
canvas{
background: hsl(184,65%,49%);
}
#picked span{
display:inline-block;
width:50px;
height:50px;
margin:3px;
text-align:center;
text-shadow:1px 1px 1px #000;
font:8px/50px Arial;
color:#fff;
}
.js .inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.inputfile + label {
max-width: 80%;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
display: inline-block;
overflow: hidden;
padding: 0.625rem 1.25rem;
}
.no-js .inputfile + label {
display: none;
}
.inputfile:focus + label,
.inputfile.has-focus + label {
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
.inputfile + label svg {
width: 1em;
height: 1em;
vertical-align: middle;
fill: currentColor;
margin-top: -0.25em;
margin-right: 0.25em;
}
.inputfile-2 + label {
width: 90%;
max-width: 220px;
background: #fff;
color: #333;
border: none;
font-family: Lato;
text-align: center;
font-size: 1vw;
padding: 25px 0 25px 0;
display: inline-block;
letter-spacing: 1px;
font-weight: 700;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 3px solid #333;
}
/* COLUMN SETUP */
.col2 {
display: block;
float:left;
margin: 0;
}
.col2:first-child { margin-left: 0; }
/* GROUPING */
.group2:before,
.group2:after { content:""; display:table; }
.group2:after { clear:both;}
.group2 { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 100%; }
.span_2_of_3 { width: 66.66%; }
.span_1_of_3 { width: 33.33%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col2 { margin: 0 }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.5%;
}
.span_2_of_4 {
width: 49%;
}
.span_1_of_4 {
width: 23.5%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
/* SECTIONS */
.section {
margin-left:5%;
margin-right:5%;
clear: both;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.5%;
}
.span_2_of_4 {
width: 49%;
}
.span_1_of_4 {
width: 23.5%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en" class="no-js">
<div id="picked"></div>
<div class="section group">
<div class="col span_1_of_4">
<input type="file" name="file_upload[]" id="file_upload" class="inputfile inputfile-2" data-multiple-caption="{count} files selected" multiple /><label for="file_upload"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg><span>CHOOSE A FILE</span></label>
</div>
<div class="col span_3_of_4">
<canvas width="600" height="300" id="canvas_picker"></canvas>
</div>
</div>
<html/>
最佳答案
抱歉代码格式化,我没有太多时间,我花了一点时间搜索才找到,但你的解决方案很优雅,所以我认为这是值得的。这是我从上次拖放实验中收集到的信息:
originalEvent
来获取文件注意:在本地页面上, header 中有 jQuery 和样式,`$(document).ready 中有脚本,在 html 之后,输入没有消失(同样,我没有时间检查原因)
//Script that hides the input box (label is a substitute)
(function(e,t,n){var r=e.querySelectorAll("html")[0];r.className=r.className.replace(/(^|\s)no-js(\s|$)/,"$1js$2")})(document,window,0);
//Hex picker function
var $picked = $("#picked"); // Just to preview picked colors
var canvas = $('#canvas_picker')[0];
var context = canvas.getContext('2d');
$("#file_upload").change(function (e) {
var F = this.files[0];
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(F);
});
$('#fileLabel').bind({
dragover: function(e){
e.preventDefault();
e.stopPropagation();
},
dragleave: function(e){
e.preventDefault();
e.stopPropagation();
},
drop: function(e){
e.preventDefault();
e.stopPropagation();
var F = e.originalEvent.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(F);
}
});
function imageIsLoaded(e) {
var img = new Image();
img.onload = function(){
canvas.width = this.width;
canvas.height = this.height;
context.drawImage(this, 0, 0);
};
img.src = e.target.result;
}
$('#canvas_picker').click(function(event){
var x = event.pageX - $(this).offset().left;
var y = event.pageY - $(this).offset().top;
var img_data = context.getImageData(x,y , 1, 1).data;
var R = img_data[0];
var G = img_data[1];
var B = img_data[2];
var rgb = R + ',' + G + ',' + B ;
var hex = rgbToHex(R,G,B);
$('#rgb input').val( rgb );
$('#hex input').val('#' + hex);
$picked.append("<span style='background:#"+hex+"'>#"+hex+"</span>");
});
function rgbToHex(R, G, B) {
return toHex(R) + toHex(G) + toHex(B);
}
function toHex(n) {
n = parseInt(n, 10);
if (isNaN(n)) return "00";
n = Math.max(0, Math.min(n, 255));
return "0123456789ABCDEF".charAt((n - n % 16) / 16) + "0123456789ABCDEF".charAt(n % 16);
}
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/dPJ5r9gl3kK6ijoeP1IRsvY6323mHUZFJMgTvxaG2iE.woff2) format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 300;
src: local('Lato Light'), local('Lato-Light'), url(http://fonts.gstatic.com/s/lato/v11/EsvMC5un3kjyUhB9ZEPPwg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
body {
background: hsl(184,65%,49%);
font-family: 'Lato';
color: #000;
font: 15px/1.4em;
}
canvas{
background: hsl(184,65%,49%);
}
#picked span{
display:inline-block;
width:50px;
height:50px;
margin:3px;
text-align:center;
text-shadow:1px 1px 1px #000;
font:8px/50px Arial;
color:#fff;
}
.js .inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.inputfile + label {
max-width: 80%;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
display: inline-block;
overflow: hidden;
padding: 0.625rem 1.25rem;
}
.no-js .inputfile + label {
display: none;
}
.inputfile:focus + label,
.inputfile.has-focus + label {
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
.inputfile + label svg {
width: 1em;
height: 1em;
vertical-align: middle;
fill: currentColor;
margin-top: -0.25em;
margin-right: 0.25em;
}
.inputfile-2 + label {
width: 90%;
max-width: 220px;
background: #fff;
color: #333;
border: none;
font-family: Lato;
text-align: center;
font-size: 1vw;
padding: 25px 0 25px 0;
display: inline-block;
letter-spacing: 1px;
font-weight: 700;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 3px solid #333;
}
/* COLUMN SETUP */
.col2 {
display: block;
float:left;
margin: 0;
}
.col2:first-child { margin-left: 0; }
/* GROUPING */
.group2:before,
.group2:after { content:""; display:table; }
.group2:after { clear:both;}
.group2 { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 100%; }
.span_2_of_3 { width: 66.66%; }
.span_1_of_3 { width: 33.33%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col2 { margin: 0 }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.5%;
}
.span_2_of_4 {
width: 49%;
}
.span_1_of_4 {
width: 23.5%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
/* SECTIONS */
.section {
margin-left:5%;
margin-right:5%;
clear: both;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.5%;
}
.span_2_of_4 {
width: 49%;
}
.span_1_of_4 {
width: 23.5%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en" class="no-js">
<div id="picked"></div>
<div class="section group">
<div class="col span_1_of_4">
<input type="file" name="file_upload[]" id="file_upload" class="inputfile inputfile-2" data-multiple-caption="{count} files selected" multiple /><label id="fileLabel" for="file_upload"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg><span>CHOOSE A FILE</span></label>
</div>
<div class="col span_3_of_4">
<canvas width="600" height="300" id="canvas_picker"></canvas>
</div>
</div>
<html/>
关于javascript - 带label标签的文件拖拽输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41633777/
运行 PostgreSQL(7.4 和 8.x),我认为这是可行的,但现在我遇到了错误。 我可以单独运行查询,它工作得很好,但如果我使用 UNION 或 UNION ALL,它会抛出错误。 这个错误:
我试图为我的应用程序创建一个导航,使用抽屉导航我的 fragment 之一(HomeFragment)有一个 ViewPager,可容纳 3 个 fragment (Bundy Clock、Annou
以我目前正在开发的应用为例: - 它有一个包含多个项目的抽屉导航;现在有两个项目让我感兴趣,我将它们称为 X 和 Y。 X 和 Y 都在单击时显示包含 x 元素或 y 元素列表的 fragment 选
我有一个形状为 (370,275,210) 的 NumPy 数组,我想将其重新整形为 (275,210,370)。我将如何在 Python 中实现这一点? 370是波段数,275是行数,210是图像包
我们如何与被子 UIViewController 阻止的父 UIViewController(具有按钮)交互。显然,触摸事件不会通过子 Nib 。 (启用用户交互) 注意:我正在加载默认和自定义 NI
我是 Jpa 新手,我想执行过程 我的代码如下 private static final String PERSISTENCE_UNIT_NAME = "todos"; private static
与安装了 LAMP 的 GCE 相比,选择与 Google Cloud SQL 链接的 GCE 实例有哪些优势? 我确定 GCE 是可扩展的,但是安装在其上的 mysql 数据库的可扩展性如何? 使用
这个问题在这里已经有了答案: Value receiver vs. pointer receiver (3 个答案) 关闭 3 年前。 我刚接触 golang。只是想了解为 Calc 类型声明的两种
我不小心按了一个快捷键,一个非常漂亮的断线出现在日期上。 有点像 # 23 Jun 2010 -------------------- 有人知道有问题的快捷方式吗?? (我在 mac 上工作!) 在
我正在Scala中编写正则表达式 val regex = "^foo.*$".r 这很好,但是如果我想做 var x = "foo" val regex = s"""^$x.*$""".r 现在我们有
以下 XML 文档在技术上是否相同? James Dean 19 和: James Dean 19 最佳答案 这两个文档在语义上是相同的。在 X
我在对数据帧列表运行稳健的线性回归模型(使用 MASS 库中的 rlm)时遇到问题。 可重现的示例: var1 <- c(1:100) var2 <- var1*var1 df1 <- data.f
好的,我有一个自定义数字键盘,可以在标签(numberField)中将数字显示为 0.00,现在我需要它显示 $0.00。 NSString *digit = sender.currentTitle;
在基于文档的应用程序中,使用 XIB 文件,创建新窗口时其行为是: 根据最后一个事件的位置进行定位和调整大小 window 。 如果最后一个事件窗口仍然可见,则新窗口 窗口应该是级联的,这样它就不会直
我想使用参数进行查询,如下所示: SELECT * FROM MATABLE WHERE MT_ID IN (368134, 181956) 所以我考虑一下 SELECT * FROM MATABLE
我遇到一些性能问题。 我有一个大约有 200 万行的表。 CREATE TABLE [dbo].[M8]( [M8_ID] [int] IDENTITY(1,1) NOT NULL,
我在 jquery 中的按键功能遇到问题。我不知道为什么按键功能不起作用。我已经使用了正确的 key 代码。在我的函数中有 2 个代码,其中包含 2 个事件键,按一个键表示 (+) 代码 107 和(
我想显示音频波形,我得到了此代码,它需要.raw音频输入并显示音频波形,但是当我放入.3gp,.mp3音频时,我得到白噪声,有人可以帮助我如何使其按需与.3gp一起使用使用.3gp音频运行它。 Inp
我无法让 stristr 函数返回真值,我相信这是因为我的搜索中有一个 $ 字符。 当我这样做时: var_dump($nopricecart); 完整的 $nopricecart 值是 $0 ,我得
如果我有这样的循环: for(int i=0;i O(n) 次。所以do some执行了O(n)次。如果做某事是线性时间,那么代码片段的复杂度是O(n^2)。 关于algorithm - 带 If 语
我是一名优秀的程序员,十分优秀!