找回密码

碧海潮声大学生网

查看: 965|回复: 2
打印 上一主题 下一主题

〖原创〗〖PW小hack〗——控制选择头像时框的图片体积限制

[复制链接]
跳转到指定楼层
1#
发表于 2005-10-24 02:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请在注册时,或资料时选择头像图片,看效果

如果头像图片原本的宽度和高于小于指定值,则不会限制
如果大于指定值,则限制其为我们指定的值,以同比例缩放

代码如下

打开template\wind\profile.htm
找到
  1. function showimage(imgpath,value)
  2. {
  3.     if(value!= '') {   
  4.     document.images.useravatars.src=imgpath+'/face/'+value;
  5.     } else{
  6.     document.images.useravatars.src=imgpath+'/face/none.gif';
  7.     }
  8. }
复制代码

替换为
  1. function showimage(imgpath,value)
  2. {
  3. var mywidth,myheight;
  4. mywidth=120; //在这里控制所能显示的图片最大尺寸,这个是宽,下面那个是长
  5. myheight=120;
  6.     if(value!= '') {   
  7.     document.images.useravatars.src=imgpath+'/face/'+value;
  8.     if (document.images.useravatars.width>mywidth)
  9.     {
  10.         document.images.useravatars.width=mywidth;
  11.         document.images.useravatars.height=document.images.useravatars.height*mywidth/document.images.useravatars.width;
  12.     }
  13.     if (document.images.useravatars.height>myheight)
  14.     {
  15.         document.images.useravatars.height=myheight;
  16.         document.images.useravatars.width=document.images.useravatars.width*myheight/document.images.useravatars.height;
  17.     }
  18.     } else{
  19.     document.images.useravatars.src=imgpath+'/face/none.gif';
  20.     }
  21. }
复制代码

同理,打开register.htm,也是找到
  1. function showimage(imgpath,value)
  2. {
  3.     if(value!= '') {   
  4.     document.images.useravatars.src=imgpath+'/face/'+value;
  5.     } else{
  6.     document.images.useravatars.src=imgpath+'/face/none.gif';
  7.     }
  8. }
复制代码
替换为
  1. function showimage(imgpath,value)
  2. {
  3. var mywidth,myheight;
  4. mywidth=120; //在这里控制所能显示的图片最大尺寸,这个是宽,下面那个是长
  5. myheight=120;
  6.     if(value!= '') {   
  7.     document.images.useravatars.src=imgpath+'/face/'+value;
  8.     if (document.images.useravatars.width>mywidth)
  9.     {
  10.         document.images.useravatars.width=mywidth;
  11.         document.images.useravatars.height=document.images.useravatars.height*mywidth/document.images.useravatars.width;
  12.     }
  13.     if (document.images.useravatars.height>myheight)
  14.     {
  15.         document.images.useravatars.height=myheight;
  16.         document.images.useravatars.width=document.images.useravatars.width*myheight/document.images.useravatars.height;
  17.     }
  18.     } else{
  19.     document.images.useravatars.src=imgpath+'/face/none.gif';
  20.     }
  21. }
复制代码

Ok,完工~其实就是修改了其自带的showimage函数,加了长和宽的判断而矣:)嘻嘻
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩
2#
发表于 2005-10-24 06:22 | 只看该作者
不错,收藏
3#
 楼主| 发表于 2005-10-24 11:59 | 只看该作者
要和那个头像选择的整合,昨天太困了先睡了,嘻嘻
所以还没上传,今天完善一下再上传
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表