我的圈子的动画css有点问题。
在我点击的地方,动画的中心显示不正确。
翻译(-50%, - 50%)仅在动画之后有效。
以下是演示:https://plnkr.co/edit/0UMwaZgBmiXWlU61EE2m
你知道如何处理这个问题吗?
var vm = new Vue({
el: "#filter-realisations",
data: {
realisations: [
{ name: "ASM", platform: "iOS", secteur: "grandPublic", secteur: "grandPublic", device:"Watch" },
{ name: "Biodiversea", platform: "Android", secteur: "marchesPublics", device:"Tablet" },
{ name: "CDBB", platform: "iOS", secteur: "grandPublic", device:"Smartphone" },
{ name: "Centre France", platform: "iOS", secteur: "grandPublic", device:"Watch" },
{ name: "Clermont", platform: "Android", secteur: "grandPublic", device:"Tablet" },
{ name: "Dassault", platform: "iOS", secteur: "metier", device:"Smartphone"},
{ name: "Journal", platform: "iOS", secteur: "metier", device:"Smartphone" },
{ name: "Somfy", platform: "Android", secteur: "metier", device:"Smartphone" },
{ name: "Sortir.vosges", platform: "Android", secteur: "metier", device:"Smartphone" },
{ name: "Sud Radio", platform: "Android", secteur: "metier", device:"Smartphone" },
{ name: "Verifrom", platform: "Android", secteur: "metier", device:"Smartphone" },
{ name: "Sports", platform: "iOS", secteur: "marchesPublics", device:"Watch" }
],
selectedSecteur : "AllSecteur",
selectedPlatform: "AllPlatform",
selectedDevice : "AllDevice"
},
computed: {
filteredRealisations: function() {
var vm = this;
var platform = vm.selectedPlatform;
var secteur = vm.selectedSecteur;
var device = vm.selectedDevice;
if(platform === "AllPlatform") {
return vm.realisations;
} else {
return vm.realisations.filter(function(app) {
return app.platform === platform;
});
}
if(secteur === "AllSecteur") {
return vm.realisations;
} else {
return vm.realisations.filter(function(app) {
return app.secteur === secteur;
});
}
if(device === "AllDevice") {
return vm.realisations;
} else {
return vm.realisations.filter(function(app) {
return app.device === device;
});
}
}
}
});
// Code goes here
function printMousePos(event) {
var element = document.getElementById("body");
var para1 = document.createElement("div");
para1.className = "circle";
para1.setAttribute("style", "position : absolute;left:" + event.clientX + "px;top:" + event.clientY + "px");
element.appendChild(para1);
var para2 = document.createElement("div");
para2.className = "point";
para2.setAttribute("style", "position : absolute;left:" + event.clientX + "px;top:" + event.clientY + "px");
element.appendChild(para2);
console.log(event.clientX, event.clientY);
}
document.addEventListener("click", printMousePos);
/* Styles go here */
body {
position: relative;
height: 1000px;
}
@keyframes circle {
from {
transform: scale(0, 0)
}
to {
transform: scale(2, 2)
}
}
.circle {
color: blue;
width: 200px;
height: 200px;
border-style: solid;
border-width: 20px;
border-color: blue;
border-radius: 50%;
transform: translate(-50%, -50%);
animation-name: circle;
animation-duration: 1s;
animation-iteration-count: 3;
/*transform-origin: 0 0;*/
}
.point {
color: red;
border-style: solid;
border-width: 5px;
border-color: red;
border-radius: 50%;
}
谢谢!
答案 0 :(得分:2)
您的关键帧标注应如下所示:
@keyframes circle {
from {
transform: scale(0,0) translate(-50%, -50%);
}
to {
transform: scale(2,2) translate(-50%, -50%);
}
}
答案 1 :(得分:2)
要开始以红点为中心的外部蓝色圆圈动画,您需要将原点转换为其中心。每次使用关键帧动画时,当您使用transform: scale(0,0);
或transform: scale(2,2);
时,中心会再次转换为默认的上角。
要解决此更改这些部分
.circle {
transform-origin: center;
}
和
@keyframes circle {
from {
transform: translate(-50%, -50%) scale(0,0);
}
to {
transform: translate(-50%, -50%) scale(2,2);
}
}
希望这能解决你的问题。