最新在线看的黄网|伊人久久久久久久网站|日本a视频专区二|欧美A级无码毛片|有扫五av在线播放|好屌日aV在线播放|内射福利视频导航|极品少妇一区二区视频|无吗在线一区播放|性爱黄色视频不卡

深圳網(wǎng)站建設(shè)公司,網(wǎng)商在線LOGO

您的位置:首頁 > 新聞

網(wǎng)頁中圖片大小自動調(diào)整四種方法
新聞 2022-11-08編輯:深圳網(wǎng)站建設(shè)閱讀(標(biāo)簽: 圖片

網(wǎng)頁中圖片大小自動調(diào)整四種方法

1.鼠標(biāo)滾動圖片大小調(diào)整

2.圖片自動縮小到固定大小
3.滾輪圖片縮放的代碼

4.內(nèi)容中的圖片大小不撐破網(wǎng)頁

鼠標(biāo)滾動圖片大小調(diào)整

<body>
<script LANGUAGE="JAVASCRIPT">
function bbimg(o){
   var zoom=parseInt(o.style.zoom, 10)||100;

zoom+=event.wheelDelta/12;

if (zoom>0)

 o.style.zoom=zoom+'%';


   return false;
}
</script> 
<img src="123.jpg" onload="javascript:if(this.width>screen.width-screen.width/2) this.style.width=screen.width-screen.width/2" onmousewheel="return bbimg(this)" > 
</body>

圖片自動縮小到固定大小

<body onload="DrawImage(theimg)">
<script language="JavaScript">
<!--
//圖片按比例縮放
var flag=false;
function DrawImage(ImgD){
  var image=new Image();
  var iwidth = 320;  //定義允許圖片寬度
  var iheight = 180;  //定義允許圖片高度
  image.src=ImgD.src;
  if(image.width>0 && image.height>0){
   flag=true;
   if(image.width/image.height>= iwidth/iheight){
    if(image.width>iwidth){  
    ImgD.width=iwidth;
    ImgD.height=(image.height*iwidth)/image.width;
    }else{
    ImgD.width=image.width;  
    ImgD.height=image.height;
    }
    ImgD.alt=image.width+"×"+image.height;
    }
   else{
    if(image.height>iheight){  
    ImgD.height=iheight;
    ImgD.width=(image.width*iheight)/image.height;     
    }else{
    ImgD.width=image.width;  
    ImgD.height=image.height;
    }
    ImgD.alt=image.width+"×"+image.height;
    }
   }
} 
//-->
</script>
<img src="123.jpg" width="1024" height="768" name="theimg">
</body> 

滾輪圖片縮放的代碼

<script language="javascript">
var count = 10;
function resizeimg(oImage)
{ 
count = Counting(count);
Resize(oImage,count);
return false;
}
function Counting(newzoom){ 
if (event.wheelDelta >= 120)
newzoom++;
else if (event.wheelDelta <= -120)
newzoom--;
if (newzoom<2) newzoom=2; ////只允許縮小到20%
if (newzoom>50) newzoom=50; ////只允許放大到500%
return newzoom; 
}
function Resize(oImage,newzoom){ 
oImage.style.zoom = newzoom + '0%'; 
count=newzoom;
}
</script>
然后在<img src="">中加入
onDblClick="return Resize(this,10);return false;" 
onmousewheel="return resizeimg(this)"

內(nèi)容中的圖片大小不撐破網(wǎng)頁

img {border: 1px solid #ddd; padding: 2px;
max-width:100%; max-height:auto;}


企業(yè)網(wǎng)站定制

企業(yè)網(wǎng)站定制 根據(jù)企業(yè)需求,量身定制設(shè)計

企業(yè)網(wǎng)站定制:2800元起
添加微信 請說明來意
聯(lián)系我們
站內(nèi)搜索

24小時服務(wù)熱線 0755-29765948
  • 地址:深圳市羅湖區(qū)人民北路2033號206
  • 電話:0755-29765948 傳真:82256610
  • 手機:13714666846 18948334877
  • 郵箱:gong@ew35.com 164761418@qq.com
  • 粵ICP備14049207號
創(chuàng)意化數(shù)字品牌整合網(wǎng)絡(luò)營銷
營銷網(wǎng)站讓你坐等商機坐傭客戶,Rss

版權(quán)所有:深圳市網(wǎng)商在線科技有限公司

友情鏈接: