说明:
我无法弄清楚为什么带有.specialItem
类动画的项目不会触发。如果你能弄清楚原因,那就太好了。背景/边框没有变化,但它不会像它应该的那样淡入淡出。
$(window).on("resize", function() {
var itemPercent = $("#percent");
var itemCE = $("#ce");
var itemC = $("#c");
var itemDEL = $("#del");
var itemDivide = $("#divide");
var itemRoot = $("#squareRoot");
var itemSeven = $("#seven");
var itemEight = $("#eight");
var itemNine = $("#nine");
var itemMultiply = $("#multiply");
var itemSupTwo = $("#supTwo");
var itemFour = $("#four");
var itemFive = $("#five");
var itemSix = $("#six");
var itemMinus = $("#minus");
var itemSupThree = $("#supThree");
var itemOne = $("#one");
var itemTwo = $("#two");
var itemThree = $("#three");
var itemPlus = $("#plus");
var itemUnSymbol = $("#unknownSymbol");
var itemPosNeg = $("#posNeg");
var itemZero = $("#zero");
var itemDecimal = $("#decimal");
var itemEquals = $("#equals");
var defaultHeightCalc = $(window).height() - $(".output").height() - $(".special").height();
$(".default").css("height", defaultHeightCalc);
var itemHeightCalc = ($(".default").height() / 5 - 13);
var itemWidthCalc = ($(".default").width() / 5 - 10);
$(".item").css({
"height": itemHeightCalc,
"width": itemWidthCalc
});
$(".itemIconAlign").css("top", ($(".item").height() / 2) - ($(".itemIconAlign").height() / 2));
}).resize();

@import url(https://fonts.googleapis.com/css?family=Droid+Sans+Mono|Pacifico|Oxygen);
body {
background: #EEEEEE;
overflow: hidden;
}
.wrapper {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
.storage {
height: 100%;
width: 19%;
position: absolute;
top: 0px;
right: 0px;
}
.main {
height: 100%;
width: 81%;
position: absolute;
top: 0px;
left: 0px;
}
.output {
height: 25%;
width: 100%;
position: relative;
top: 0px;
left: 0px;
font-family: 'Roboto', sans-serif;
font-weight: 900;
font-size: 104px;
text-align: right;
}
.numLineAlign {
position: relative;
top: 30%;
right: 0px;
width: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.input {
width: 100%;
position: relative;
top: 0%;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.special {
height: 50px;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
}
.default {
width: 100%;
position: absolute;
top: 50px;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageNav {
height: 70px;
width: 100%;
position: relative;
top: 0px;
right: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageTab {
height: 25%;
position: relative;
top: 25%;
left: 0px;
color: black;
text-align: center;
padding: 20px;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 600;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.item {
text-align: center;
background: white;
display: inline-block;
margin: 2px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
min-height: 50px;
}
.item:hover {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
#percent, #ce, #c, #del, #divide, #decimal, #minus, #plus, #equals,
#squareRoot, #supTwo, #supThree, #unknownSymbol, #posNeg, #multiply {
background: #E0E0E0;
font-family: 'Raleway', sans-serif;
font-weight: 400;
font-size: 20px;
}
#one, #two, #three, #four, #five,
#six, #seven, #eight, #nine, #zero {
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 20px;
}
.itemIconAlign {
position: relative;
left: 0px;
}
.specialItem {
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 12px;
text-align: center;
padding: 25px;
margin-top: -23px;
cursor: pointer;
border: 2px solid transparent;
}
.specialItem:hover {
background: #E0E0E0;
border: 2px solid white;
animation: fade 1s;
}
@keyframes fade {
0% {
background: #E0E0E0;
border: 2px solid white;
}
100% {
background: #E0E0E0;
border: 2px solid white;
}
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="storage">
<div class="storageNav">
<div class="storageTab">History</div>
<div class="storageTab">Memory</div>
</div>
<div class="storageBox">
</div>
</div>
<div class="main">
<div class="output">
<div class="numLineAlign">
0
</div>
</div>
<div class="input">
<div class="special">
<div class="specialItem" id="memClean">MC</div>
<div class="specialItem" id="memRead">MR</div>
<div class="specialItem" id="memAdd">M+</div>
<div class="specialItem" id="memRemove">M-</div>
<div class="specialItem" id="memStore">MS</div>
</div>
<div class="default">
<div class="row" id="r1">
<div class="item" id="percent">
<div class="itemIconAlign">%</div>
</div>
<div class="item" id="ce">
<div class="itemIconAlign">CE</div>
</div>
<div class="item" id="c">
<div class="itemIconAlign">C</div>
</div>
<div class="item" id="del">
<div class="itemIconAlign">DEL</div>
</div>
<div class="item" id="divide">
<div class="itemIconAlign">÷</div>
</div>
</div>
<div class="row" id="r2">
<div class="item" id="squareRoot">
<div class="itemIconAlign">√</div>
</div>
<div class="item" id="seven">
<div class="itemIconAlign">7</div>
</div>
<div class="item" id="eight">
<div class="itemIconAlign">8</div>
</div>
<div class="item" id="nine">
<div class="itemIconAlign">9</div>
</div>
<div class="item" id="multiply">
<div class="itemIconAlign">*</div>
</div>
</div>
<div class="row" id="r3">
<div class="item" id="supTwo">
<div class="itemIconAlign">x<sup>2</sup></div>
</div>
<div class="item" id="four">
<div class="itemIconAlign">4</div>
</div>
<div class="item" id="five">
<div class="itemIconAlign">5</div>
</div>
<div class="item" id="six">
<div class="itemIconAlign">6</div>
</div>
<div class="item" id="minus">
<div class="itemIconAlign">-</div>
</div>
</div>
<div class="row" id="r4">
<div class="item" id="supThree">
<div class="itemIconAlign">x<sup>3</sup></div>
</div>
<div class="item" id="one">
<div class="itemIconAlign">1</div>
</div>
<div class="item" id="two">
<div class="itemIconAlign">2</div>
</div>
<div class="item" id="three">
<div class="itemIconAlign">3</div>
</div>
<div class="item" id="plus">
<div class="itemIconAlign">+</div>
</div>
</div>
<div class="row" id="r5">
<div class="item" id="unknownSymbol">
<div class="itemIconAlign"><sup>1</sup>/x</div>
</div>
<div class="item" id="posNeg">
<div class="itemIconAlign">±</div>
</div>
<div class="item" id="zero">
<div class="itemIconAlign">0</div>
</div>
<div class="item" id="decimal">
<div class="itemIconAlign">●</div>
</div>
<div class="item" id="equals">
<div class="itemIconAlign">=</div>
</div>
</div>
</div>
</div>
</div>
</div>
&#13;
答案 0 :(得分:1)
您需要在动画的0%和100%上使用不同的值。
@keyframes fade {
0% {background: #EEE; border: 2px solid #EEE;}
100% {}
}
此外,您可以删除动画并使用转换,通常只使用0%和100%时,您可以使用简单转换。
.specialItem {
transition: all 1s;
}
.specialItem:hover {
background: #E0E0E0;
border: 2px solid white;
}
请参阅下面的代码段。
$(window).on("resize", function() {
var itemPercent = $("#percent");
var itemCE = $("#ce");
var itemC = $("#c");
var itemDEL = $("#del");
var itemDivide = $("#divide");
var itemRoot = $("#squareRoot");
var itemSeven = $("#seven");
var itemEight = $("#eight");
var itemNine = $("#nine");
var itemMultiply = $("#multiply");
var itemSupTwo = $("#supTwo");
var itemFour = $("#four");
var itemFive = $("#five");
var itemSix = $("#six");
var itemMinus = $("#minus");
var itemSupThree = $("#supThree");
var itemOne = $("#one");
var itemTwo = $("#two");
var itemThree = $("#three");
var itemPlus = $("#plus");
var itemUnSymbol = $("#unknownSymbol");
var itemPosNeg = $("#posNeg");
var itemZero = $("#zero");
var itemDecimal = $("#decimal");
var itemEquals = $("#equals");
var defaultHeightCalc = $(window).height() - $(".output").height() - $(".special").height();
$(".default").css("height", defaultHeightCalc);
var itemHeightCalc = ($(".default").height() / 5 - 13);
var itemWidthCalc = ($(".default").width() / 5 - 10);
$(".item").css({ "height" : itemHeightCalc, "width" : itemWidthCalc });
$(".itemIconAlign").css("top", ($(".item").height() / 2) - ($(".itemIconAlign").height() / 2));
}).resize();
@import url(https://fonts.googleapis.com/css?family=Droid+Sans+Mono|Pacifico|Oxygen);
body {
background: #EEEEEE;
overflow: hidden;
}
.wrapper {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
.storage {
height: 100%;
width: 19%;
position: absolute;
top: 0px;
right: 0px;
}
.main {
height: 100%;
width: 81%;
position: absolute;
top: 0px;
left: 0px;
}
.output {
height: 25%;
width: 100%;
position: relative;
top: 0px;
left: 0px;
font-family: 'Roboto', sans-serif;
font-weight: 900;
font-size: 104px;
text-align: right;
}
.numLineAlign {
position: relative;
top: 30%;
right: 0px;
width: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.input {
width: 100%;
position: relative;
top: 0%;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.special {
height: 50px;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
}
.default {
width: 100%;
position: absolute;
top: 50px;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageNav {
height: 70px;
width: 100%;
position: relative;
top: 0px;
right: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageTab {
height: 25%;
position: relative;
top: 25%;
left: 0px;
color: black;
text-align: center;
padding: 20px;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 600;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.item {
text-align: center;
background: white;
display: inline-block;
margin: 2px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
min-height: 50px;
}
.item:hover {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
#percent, #ce, #c, #del, #divide, #decimal, #minus, #plus, #equals, #squareRoot, #supTwo, #supThree, #unknownSymbol, #posNeg, #multiply {
background: #E0E0E0;
font-family: 'Raleway', sans-serif;
font-weight: 400;
font-size: 20px;
}
#one, #two, #three, #four, #five, #six, #seven, #eight, #nine, #zero {
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 20px;
}
.itemIconAlign {
position: relative;
left: 0px;
}
.specialItem {
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 12px;
text-align: center;
padding: 25px;
margin-top: -23px;
cursor: pointer;
border: 2px solid transparent;
}
.specialItem {
transition: all 1s;
}
.specialItem:hover {
background: #E0E0E0;
border: 2px solid white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="storage">
<div class="storageNav">
<div class="storageTab">History</div>
<div class="storageTab">Memory</div>
</div>
<div class="storageBox">
</div>
</div>
<div class="main">
<div class="output">
<div class="numLineAlign">
0
</div>
</div>
<div class="input">
<div class="special">
<div class="specialItem" id="memClean">MC</div>
<div class="specialItem" id="memRead">MR</div>
<div class="specialItem" id="memAdd">M+</div>
<div class="specialItem" id="memRemove">M-</div>
<div class="specialItem" id="memStore">MS</div>
</div>
<div class="default">
<div class="row" id="r1">
<div class="item" id="percent">
<div class="itemIconAlign">%</div>
</div>
<div class="item" id="ce">
<div class="itemIconAlign">CE</div>
</div>
<div class="item" id="c">
<div class="itemIconAlign">C</div>
</div>
<div class="item" id="del">
<div class="itemIconAlign">DEL</div>
</div>
<div class="item" id="divide">
<div class="itemIconAlign">÷</div>
</div>
</div>
<div class="row" id="r2">
<div class="item" id="squareRoot">
<div class="itemIconAlign">√</div>
</div>
<div class="item" id="seven">
<div class="itemIconAlign">7</div>
</div>
<div class="item" id="eight">
<div class="itemIconAlign">8</div>
</div>
<div class="item" id="nine">
<div class="itemIconAlign">9</div>
</div>
<div class="item" id="multiply">
<div class="itemIconAlign">*</div>
</div>
</div>
<div class="row" id="r3">
<div class="item" id="supTwo">
<div class="itemIconAlign">x<sup>2</sup></div>
</div>
<div class="item" id="four">
<div class="itemIconAlign">4</div>
</div>
<div class="item" id="five">
<div class="itemIconAlign">5</div>
</div>
<div class="item" id="six">
<div class="itemIconAlign">6</div>
</div>
<div class="item" id="minus">
<div class="itemIconAlign">-</div>
</div>
</div>
<div class="row" id="r4">
<div class="item" id="supThree">
<div class="itemIconAlign">x<sup>3</sup></div>
</div>
<div class="item" id="one">
<div class="itemIconAlign">1</div>
</div>
<div class="item" id="two">
<div class="itemIconAlign">2</div>
</div>
<div class="item" id="three">
<div class="itemIconAlign">3</div>
</div>
<div class="item" id="plus">
<div class="itemIconAlign">+</div>
</div>
</div>
<div class="row" id="r5">
<div class="item" id="unknownSymbol">
<div class="itemIconAlign"><sup>1</sup>/x</div>
</div>
<div class="item" id="posNeg">
<div class="itemIconAlign">±</div>
</div>
<div class="item" id="zero">
<div class="itemIconAlign">0</div>
</div>
<div class="item" id="decimal">
<div class="itemIconAlign">●</div>
</div>
<div class="item" id="equals">
<div class="itemIconAlign">=</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
它正在工作! (至少在Chrome中)
问题在于动画不会改变任何内容,而是动画的@keyframes
与:hover
中设置的值完全相同。
我更改了关键帧的值以显示差异。
$(window).on("resize", function() {
var itemPercent = $("#percent");
var itemCE = $("#ce");
var itemC = $("#c");
var itemDEL = $("#del");
var itemDivide = $("#divide");
var itemRoot = $("#squareRoot");
var itemSeven = $("#seven");
var itemEight = $("#eight");
var itemNine = $("#nine");
var itemMultiply = $("#multiply");
var itemSupTwo = $("#supTwo");
var itemFour = $("#four");
var itemFive = $("#five");
var itemSix = $("#six");
var itemMinus = $("#minus");
var itemSupThree = $("#supThree");
var itemOne = $("#one");
var itemTwo = $("#two");
var itemThree = $("#three");
var itemPlus = $("#plus");
var itemUnSymbol = $("#unknownSymbol");
var itemPosNeg = $("#posNeg");
var itemZero = $("#zero");
var itemDecimal = $("#decimal");
var itemEquals = $("#equals");
var defaultHeightCalc = $(window).height() - $(".output").height() - $(".special").height();
$(".default").css("height", defaultHeightCalc);
var itemHeightCalc = ($(".default").height() / 5 - 13);
var itemWidthCalc = ($(".default").width() / 5 - 10);
$(".item").css({ "height" : itemHeightCalc, "width" : itemWidthCalc });
$(".itemIconAlign").css("top", ($(".item").height() / 2) - ($(".itemIconAlign").height() / 2));
}).resize();
@import url(https://fonts.googleapis.com/css?family=Droid+Sans+Mono|Pacifico|Oxygen);
body {
background: #EEEEEE;
overflow: hidden;
}
.wrapper {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
.storage {
height: 100%;
width: 19%;
position: absolute;
top: 0px;
right: 0px;
}
.main {
height: 100%;
width: 81%;
position: absolute;
top: 0px;
left: 0px;
}
.output {
height: 25%;
width: 100%;
position: relative;
top: 0px;
left: 0px;
font-family: 'Roboto', sans-serif;
font-weight: 900;
font-size: 104px;
text-align: right;
}
.numLineAlign {
position: relative;
top: 30%;
right: 0px;
width: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.input {
width: 100%;
position: relative;
top: 0%;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.special {
height: 50px;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
}
.default {
width: 100%;
position: absolute;
top: 50px;
left: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageNav {
height: 70px;
width: 100%;
position: relative;
top: 0px;
right: 0px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.storageTab {
height: 25%;
position: relative;
top: 25%;
left: 0px;
color: black;
text-align: center;
padding: 20px;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 600;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.item {
text-align: center;
background: white;
display: inline-block;
margin: 2px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
min-height: 50px;
}
.item:hover {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
#percent, #ce, #c, #del, #divide, #decimal, #minus, #plus, #equals, #squareRoot, #supTwo, #supThree, #unknownSymbol, #posNeg, #multiply {
background: #E0E0E0;
font-family: 'Raleway', sans-serif;
font-weight: 400;
font-size: 20px;
}
#one, #two, #three, #four, #five, #six, #seven, #eight, #nine, #zero {
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 20px;
}
.itemIconAlign {
position: relative;
left: 0px;
}
.specialItem {
display: inline-block;
font-family: 'Raleway', sans-serif;
font-weight: 800;
font-size: 12px;
text-align: center;
padding: 25px;
margin-top: -23px;
cursor: pointer;
border: 2px solid transparent;
}
.specialItem:hover {
animation: fade 1s;
}
@keyframes fade {
0% {background: transparent; border: 2px solid transparent;}
100% {background: #E0E0E0; border: 2px solid white;}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="storage">
<div class="storageNav">
<div class="storageTab">History</div>
<div class="storageTab">Memory</div>
</div>
<div class="storageBox">
</div>
</div>
<div class="main">
<div class="output">
<div class="numLineAlign">
0
</div>
</div>
<div class="input">
<div class="special">
<div class="specialItem" id="memClean">MC</div>
<div class="specialItem" id="memRead">MR</div>
<div class="specialItem" id="memAdd">M+</div>
<div class="specialItem" id="memRemove">M-</div>
<div class="specialItem" id="memStore">MS</div>
</div>
<div class="default">
<div class="row" id="r1">
<div class="item" id="percent">
<div class="itemIconAlign">%</div>
</div>
<div class="item" id="ce">
<div class="itemIconAlign">CE</div>
</div>
<div class="item" id="c">
<div class="itemIconAlign">C</div>
</div>
<div class="item" id="del">
<div class="itemIconAlign">DEL</div>
</div>
<div class="item" id="divide">
<div class="itemIconAlign">÷</div>
</div>
</div>
<div class="row" id="r2">
<div class="item" id="squareRoot">
<div class="itemIconAlign">√</div>
</div>
<div class="item" id="seven">
<div class="itemIconAlign">7</div>
</div>
<div class="item" id="eight">
<div class="itemIconAlign">8</div>
</div>
<div class="item" id="nine">
<div class="itemIconAlign">9</div>
</div>
<div class="item" id="multiply">
<div class="itemIconAlign">*</div>
</div>
</div>
<div class="row" id="r3">
<div class="item" id="supTwo">
<div class="itemIconAlign">x<sup>2</sup></div>
</div>
<div class="item" id="four">
<div class="itemIconAlign">4</div>
</div>
<div class="item" id="five">
<div class="itemIconAlign">5</div>
</div>
<div class="item" id="six">
<div class="itemIconAlign">6</div>
</div>
<div class="item" id="minus">
<div class="itemIconAlign">-</div>
</div>
</div>
<div class="row" id="r4">
<div class="item" id="supThree">
<div class="itemIconAlign">x<sup>3</sup></div>
</div>
<div class="item" id="one">
<div class="itemIconAlign">1</div>
</div>
<div class="item" id="two">
<div class="itemIconAlign">2</div>
</div>
<div class="item" id="three">
<div class="itemIconAlign">3</div>
</div>
<div class="item" id="plus">
<div class="itemIconAlign">+</div>
</div>
</div>
<div class="row" id="r5">
<div class="item" id="unknownSymbol">
<div class="itemIconAlign"><sup>1</sup>/x</div>
</div>
<div class="item" id="posNeg">
<div class="itemIconAlign">±</div>
</div>
<div class="item" id="zero">
<div class="itemIconAlign">0</div>
</div>
<div class="item" id="decimal">
<div class="itemIconAlign">●</div>
</div>
<div class="item" id="equals">
<div class="itemIconAlign">=</div>
</div>
</div>
</div>
</div>
</div>
</div>