基于rapheal图片放大 缩小 旋转 拖拽 双击

rapheal中文api:http://html5css3webapp.com/raphaelApi.htm

Raphael Javascript 是一个 Javascript的矢量库。

英文原版官网:http://raphaeljs.com

英文原版文档:http://raphaeljs.com/reference.html

rapheal这个玩意儿可以实现很多很负载的功能,这次只用到了图片的简单处理,再此记录

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>demo</title>
        <link rel="stylesheet" href="demo.css" media="screen">
        <script src="raphael-min.js"></script>
        <script src="jquery.js"></script>
        <style media="screen">
            body {
                background: #333;
            }
        </style>
    </head>
    <body>
        <div id="holder" width="100%" >
          <div style="position:fixed;bottom:0px;"><button id="load">Load</button><button id="max">Enlargement</button><button id="min">Reduction</button><button id="left">Left</button><button id="right">Right</button></div>
          <img id="photo" src="demo.png" style='display:none'/>
        </div>
        
        <script type="text/javascript">
        var paper;
        var image;
        var image_width=0;
        var image_height=0;
        var image_x;
        var image_y;
         $(function () {
          paper = Raphael("holder", 800, 800);  
          dragImg=function(dx,dy,x,y,event){
          image.animate({x:dx+image_x,y:dy+image_y});
         }
        });
        </script>
        <script type="text/javascript">
        $("#load").click(function(){  
            if(image){ image.unhover();image.undblclick();image.remove();}
            paper.clear();
            image_width=$("#photo").width();
            image_height=$("#photo").height();
            image = paper.image("demo.png", 50, 50, image_width, image_height);
            //鼠标显示
            image.attr('cursor','pointer');
            //拖拽事件
            image.drag(dragImg,function(x,y){image_x=image.attr("x");image_y=image.attr("y");});
            //双击事件
            image.dblclick(function(){image.scale(1.25,1.25)});
        });
        //点击缩小按钮
         $("#min").mousedown(function(){ 
          if(!image) return;
            interval = setInterval(function() {  
               image.scale(0.95,0.95);
            }, 100);  
          });
          $("#min").mouseup(function(){ 
          if(!image) return;
            clearInterval(interval);  
          });
          //点击放大按钮
          $("#max").mousedown(function(){ 
          if(!image) return;
            interval = setInterval(function() {  
               image.scale(1.05,1.05);
            }, 100);  
          });
          $("#max").mouseup(function(){ 
          if(!image) return;
            clearInterval(interval);  
          });
          //点击左转按钮
          $("#left").mousedown(function(){ 
          if(!image) return;
            interval = setInterval(function() {  
                image.rotate(-2); 
            }, 100);  
          });
          $("#left").mouseup(function(){ 
          if(!image) return;
            clearInterval(interval);  
          });
          //点击右转按钮
          $("#right").mousedown(function(){ 
          if(!image) return;
            interval = setInterval(function() {  
                image.rotate(2); 
            }, 100);  
          });
          $("#right").mouseup(function(){ 
          if(!image) return;
            clearInterval(interval);  
          });
      
        </script>
    </body>
</html>
#holder {
    height: 480px;
    left: 50%;
    margin: -240px 0 0 -320px;
    position: absolute;
    top: 50%;
    width: 640px;
}


显示效果:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值