Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->网站设计 ->JavaScript ->正文

用来实现Web页面图片移动托拽的代码段

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-05 点击: [收藏] [投稿]

        {
            src=event.srcElement;
            halfwidth=src.width/2;
            drag=true;
           
            //  方向の判断
            if(event.clientX<src.getClientRects()[0].left+halfwidth)
            {
                dir="Backward";
                refer=src.getClientRects()[0].left+src.width;
            }
            else
            {
                dir="Forward";
                refer=src.getClientRects()[0].left;
            }
           
            //  操作の判断:1.移動・2.縮小/拡大
            if(event.shiftLeft)
            {
                ope="Move";
                refer=event.clientX-src.getClientRects()[0].left;
            }
            else
            {
                ope="Scale";
            }
        }
        else
        {
            if(ope=="Scale")
            {
                var sleft=Math.ceil((src.getClientRects()[0].left-left)/unit-1)*unit+left;
                var header=src.getClientRects()[0].left-src.getClientRects()[0].left;
                var tail=src.width-header-Math.ceil((src.width-header)/unit)*unit;
                var swidth=Math.ceil((src.width-header)/unit)*unit;
                if(header>0)
                {
                    swidth=swidth+unit;
                }
                if(tail>0)
                {
                    swidth=swidth+unit;
                }
                src.style.left=sleft;
                src.width=swidth;
            }
           
            if(ope=="Move")
            {
                src.style.left=Math.ceil((src.getClientRects()[0].left-left)/unit-1)*unit+left;
            }
           

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:开发跨浏览器JavaScript时要注意的问题   下一篇:限制文本字节数的JS源代码程序

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号