- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我设法做了一些修改来缩放拉斐尔纸,因为 setviewbox 不适合我,这是我编写的函数:
function setCTM(element, matrix) {
var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
element.setAttribute("transform", s);
}
Raphael.fn.zoomAndMove = function(coordx,coordy,zoom) {
var svg = document.getElementsByTagName("svg")[0];
var z = zoom;
var g = document.getElementById("viewport1");
var p = svg.createSVGPoint();
p.x = coordx;
p.y = coordy;
p = p.matrixTransform(g.getCTM().inverse());
var k = svg.createSVGMatrix().scale(z).translate(-p.x, -p.y);
setCTM(g, g.getCTM().multiply(k));
}
其中 viewport1 元素定义为:
var gelem = document.createElementNS('http://www.w3.org/2000/svg', 'g');
gelem.id = 'viewport1';
paper.canvas.appendChild(gelem);
paper.canvas = gelem;
然后我可以调用:paper.zoomAndMove(minx,miny,zoomRatio);
是否可以对函数进行改造,使其平滑缩放?
最佳答案
对于任何想要平滑缩放和平移动画的人(像我一样),请看这里:
https://groups.google.com/forum/?fromgroups#!topic/raphaeljs/7eA9xq4enDo
这个片段帮助我自动缩放和平移到 Canvas 上的特定点并设置动画。 (支持Will Morgan)
Raphael.fn.animateViewBox = function(currentViewBox, viewX, viewY, width, height, duration, callback) {
duration = duration || 250;
var originals = currentViewBox, //current viewBox Data from where the animation should start
differences = {
x: viewX - originals.x,
y: viewY - originals.y,
width: width - originals.width,
height: height - originals.height
},
delay = 13,
stepsNum = Math.ceil(duration / delay),
stepped = {
x: differences.x / stepsNum,
y: differences.y / stepsNum,
width: differences.width / stepsNum,
height: differences.height / stepsNum
}, i,
canvas = this;
/**
* Using a lambda to protect a variable with its own scope.
* Otherwise, the variable would be incremented inside the loop, but its
* final value would be read at run time in the future.
*/
function timerFn(iterator) {
return function() {
canvas.setViewBox(
originals.x + (stepped.x * iterator),
originals.y + (stepped.y * iterator),
originals.width + (stepped.width * iterator),
originals.height + (stepped.height * iterator)
);
// Run the callback as soon as possible, in sync with the last step
if(iterator == stepsNum && callback) {
callback(viewX, viewY, width, height);
}
}
}
// Schedule each animation step in to the future
// Todo: use some nice easing
for(i = 1; i <= stepsNum; ++i) {
setTimeout(timerFn(i), i * delay);
}
}
关于jquery - 拉斐尔纸缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736690/
我试图学习python并以此开始,当我尝试运行它时,我一直收到语法错误。光标跳到def start部分的close结束处。我不确定语法错误来自哪里,因为我用语音标记了所有打印件 #! python3
在我的应用程序中,我使用了 polymer 的 paper-dialog 元素。对话框的样式总是将它定位在中心,但我希望它在对话框和窗口右侧之间设置一个最小距离,所以当窗口缩小时,纸质对话框不会靠近右
我需要实现一个石头剪刀布锦标赛模拟器,它将玩完所有回合并返回锦标赛。 这是我的锦标赛数组: tournament = [ [ [ ["Armando",
所以我实际上是用自定义元素包装标准 paper-slider 元素,并希望包含一些样式。以下是我目前拥有的: /* Works */ paper-slider {
对于仅包含图像的 HTML 文档,如何缩放图像以填满整个工作表?我希望图像缩放它的宽度/高度以尽可能大/尽可能小以适合一张纸。 我开始用它来分页 footer {page-break-after:al
我正在尝试扩展 Polymer paper-slider 元素,以便能够获取枚举列表并在 slider 中迭代这些值,而不是仅显示数值。但是我在使样式起作用时遇到了麻烦。如您所见,如果您运行此代码片段
我是 paper.js 的新手。 对于这个项目,我需要一个将在许多情况下使用的形状(具有不同的填充颜色),因此使用符号显然更好(而不是使用 Path.clone() 方法)。但是,一旦我将符号实例化为
我想重新组合我的 PDF 文档以使用我的打印机的 A4 格式在 A5 上打印它们。 我还需要在每个 A5 页面上打印两个站点(幻灯片),当然应该是双面的。因此 A4 页面是横向格式。比我想把它剪在中间
我有两个元素一个在另一个上面,也就是说,一个挡住了另一个。假设 Item2 被 Item1 阻止。现在每当我使用 project.hitTest(Item2); 它工作正常。 但是当我使用鼠标的eve
我有一个网站,它本质上是一个大 Canvas 图像。目前,当 body 被加载时,它开始通过这段代码淡入: 但是我想在我的 paperscript 中调用它,因为有时 body 会在图像从 pape
我是一名优秀的程序员,十分优秀!