我在我的代码中使用someMap.get(someKey)
,这给了我一个错误,说Please use !! or ?
. 当我使用时someMap.getValue(someKey)
,该错误消失了。
有人能解释一下为什么我们在课堂上有两个看似相似(但奇怪地不同)的get
函数吗Map
?
更新
我猜这与引发异常的异常有关getValue
。但 Kotlin 不是没有异常抛出吗?
我尝试使用过渡创建此效果.看起来你应该打开一个盒子.
有两个问题:
我希望如果解决方案是纯CSS,请不要使用JavaScript.
#box {
position: relative;
top: 170px;
left: 170px;
width: 300px;
height: 300px;
border: 1px solid black;
perspective: 800px;
}
#flap1, #flap2, #flap3, #flap4 {
position: absolute;
}
#flap1 {
background-color: red;
width: 150px;
height: 300px;
z-index: 1;
transform-origin: 0 0;
transition: transform 1s;
}
#flap2 {
left: 150px;
background-color: blue;
width: 150px;
height: 300px;
z-index: 1;
transform-origin: 100% 0;
transition: transform 1s ease 0.3s;
}
#flap3 {
background-color: green;
width: 300px;
height: 150px;
transform-origin: 0 …
Run Code Online (Sandbox Code Playgroud)我正在学习创建立方体旋转效果.悬停如果我更换rotateX
由rotateY
立方体为中心Y轴旋转.但是当rotateX
存在时,立方体不会围绕X轴居中旋转.如何实现立方体的正确旋转?
#container {
perspective: 1000px;
perspective-origin: 0 0;
}
#cube {
position: relative;
top: 100px;
left: 100px;
width: 200px;
transform-style: preserve-3d;
transition: transform 2s;
transform-origin: 50% 50%;
}
#cube div {
position: absolute;
width: 200px;
height: 200px;
}
#front {
transform: rotateY( 0deg ) translateZ( 100px );
background-color: rgba(0,34,62,0.3);
}
#right {
transform: rotateY( 90deg ) translateZ( 100px );
background-color: rgba(110,34,162,0.3);
}
#back {
transform: rotateY( 180deg ) translateZ( 100px );
background-color: rgba(20,4,62,0.3);
} …
Run Code Online (Sandbox Code Playgroud)我创建了这个动画,但它并不流畅.当您将鼠标悬停在蓝色圆圈上时,会打开一个彩色圆圈,但开口不稳定,不是100%平滑.动画可以平滑,怎么样?
#container {
border: 1px solid black;
width: 600px;
height: 600px;
position: relative;
}
#circle {
margin: 0;
padding: 0;
border: 1px solid black;
width: 50px;
height: 50px;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
transition: width 0.2s, height 0.2s;
}
#circle a {
margin: 0;
display: block;
padding: 0;
width: 250px;
height: 220px;
position: absolute;
top: 50%;
left: 50%;
transform-origin: 0 0;
}
#circle a:hover {
opacity: 0.5;
cursor: pointer;
}
#trap1 { …
Run Code Online (Sandbox Code Playgroud)我创建了这种储物柜打开类型的效果,但是没有厚门,看起来不太好。如何增加门的厚度,使其看起来像储物柜门?我还能做些什么来让它看起来更真实吗?
请仅使用 CSS 解决方案,不要使用 JavaScript。
#container {
width: 100%;
height: 600px;
position: relative;
}
#maincircle {
width: 200px;
height: 200px;
position: absolute;
top: 200px;
left: 50%;
transform: translateX(-50%);
border-radius: 50%;
border: 1px solid black;
perspective: 600px;
transform-style: preserve-3d;
}
#door, #back {
border-radius: 50%;
background-color: grey;
top: 1px;
left: 1px;
position: absolute;
width: 99%;
height: 99%;
transition: transform 2s 0.5s;
transform-origin: 0 50%;
}
#door {
backface-visibility: hidden;
}
#locker {
position: absolute;
top: 25px;
left: 25px;
border-radius: 50%;
width: …
Run Code Online (Sandbox Code Playgroud)我有一个 Kotlin 列表。我需要从列表的每个元素创建一个映射到一个空的可变集,如下所示 -
var mutableMap: MutableMap<Int, MutableSet<Int>> = mutableMapOf(someList.map{ it to mutableSetOf<Int>() })
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误 -
Type mismatch.
Required:
Pair<TypeVariable(K), TypeVariable(V)>
Found:
List<Pair<Int, MutableSet<Int>>>
Run Code Online (Sandbox Code Playgroud)
我知道 mutableMapOf() 接受varargs pairs
,所以我尝试了扩展运算符 ( *
),但这也不起作用。请帮助我实现结果。
我知道glutMainLoop()用于一遍又一遍地调用显示,以保持恒定的帧速率。同时,如果我还有glutTimerFunc(),它在最后调用glutPostRedisplay(),因此它可以保持不同的帧速率。
当他们一起工作时,真正发生了什么?计时器功能是否会增加主循环的帧速率并使其更快?还是会更改主循环的默认刷新率?它们如何协同工作?
即使我添加了保证金:auto; .content类实际上是模态的内容,它仍然位于左上角.为什么会这样?我怎样才能将它对齐?
var mod=document.getElementById("myModal");
var img= document.getElementById("image");
img.addEventListener("click",animate);
function animate() {
mod.style.display = "block";
}
Run Code Online (Sandbox Code Playgroud)
#image {
width: 400px;
cursor: pointer;
}
.modal {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(0,0,0,0.9);
}
.content {
margin: auto;
width: 800px;
animation-name: zoom;
animation-duration: 0.6s;
}
@keyframes zoom {
from {transform: scale(0.1);}
to {transform: scale(1);}
}
Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<img id="image" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
<div id="myModal" class="modal">
<img class="content" id="image01" src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg">
</div> …
Run Code Online (Sandbox Code Playgroud)我是科特林新手。我总是使用带花括号的地图变换。然后 -
为什么这有效 ->
val x = someList.map(::SomeConstructor)
Run Code Online (Sandbox Code Playgroud)
这不是吗?
val x = someList.map{ ::SomeConstructor }
Run Code Online (Sandbox Code Playgroud)
我在在线教程的任何地方都没有找到带圆括号的地图的用法。
请尽量详细解释一下,或者提供合适的参考文章。
我有这张桌子->
+----+-----------+-----------+
| id | gainOnX | gainOnY |
+----+-----------+-----------+
| 1 | 10 | 10 |
| 1 | -5 | 5 |
| 2 | -5 | -10 |
| 2 | -10 | 5 |
+----+-----------+-----------+
Run Code Online (Sandbox Code Playgroud)
我需要按 id 对这些数据进行分组,但我需要 4 列
所以它应该看起来像这样 ->
+----+---------+-------+---------+-------+
| id | profitX | lossX | profitY | lossY |
+----+---------+-------+---------+-------+
| 1 | 10 | …
Run Code Online (Sandbox Code Playgroud)