Rapha?l 鼠标拖动,滚轮缩放js代码
2018-07-20 来源:open-open
$(window).load(function() {
var p = Raphael('canvas');
p.cx = 0, p.cy = 0, p.cs = 1;
p.canvas.style.backgroundColor = '#008080';
$(window).resize(function() {
p.setSize($('#canvas').width(), $('#canvas').height());
});
$(p.canvas).on('mousedown', function(e) {
if (e.target == p.canvas) {
this.ox = e.offsetX;
this.oy = e.offsetY;
}
});
$(p.canvas).on('mousemove', function(e) {
if (e.target == p.canvas && this.ox) {
var size = p.getSize();
p.cx = p.cx - (e.offsetX - this.ox) / p.cs;
p.cy = p.cy - (e.offsetY - this.oy) / p.cs;
p.setViewBox(p.cx, p.cy, size.width / p.cs, size.height / p.cs);
this.ox = e.offsetX;
this.oy = e.offsetY;
}
});
$(p.canvas).on('mouseup', function(e) {
if (e.target == p.canvas && this.ox) {
delete this.ox;
delete this.oy;
}
});
$(p.canvas).on('mousewheel', function(e) {
if (e.target == p.canvas) {
var size = p.getSize();
p.cs2 = e.originalEvent.wheelDelta > 0 ? p.cs * 1.125 : p.cs / 1.125;
p.cx = p.cx + (e.offsetX / p.cs - e.offsetX / p.cs2);
p.cy = p.cy + (e.offsetY / p.cs - e.offsetY / p.cs2);
p.cs = p.cs2;
p.setViewBox(p.cx, p.cy, size.width / p.cs, size.height / p.cs);
}
return false;
});
for (var i = 0; i < 200; i++) {
var r = Math.random;
p.rect(700 * r(), 500 * r(), 100 * r(), 100 * r()).attr('fill', '#00ffff');
}
});
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:JS小数点保留
下一篇:Java实现打字练习的代码
最新资讯
热门推荐