技術(shù)文章
js 實現(xiàn)圖片指向時變透明、JS控制圖片最大寬度
發(fā)布日期:2014-07-20 閱讀次數(shù):3395 字體大小:

js 實現(xiàn)圖片指向時變透明、JS控制圖片最大寬度

  1. 新建 JS.JS文檔,將以下代碼粘貼并保存。
  2. 新建 index.html 文件,引用JS文檔如:<script type="text/javascript" src="http://www.002bubu.com/js/common.js"></script>
  3. 在引用圖片時使用如下代碼_信息來源 亳州網(wǎng)絡公司 易天科技
  4.  
  5. JavaScript代碼
    1. $(function () {  
    2.       
    3.   
    4. //案例變透明  
    5. $(".pro_img img,.pro_img2 img,.temp_img img").hover(function(){  
    6. $(this).fadeTo("fast",0.8)  
    7. },function(){  
    8. $(this).fadeTo("fast",1)    
    9. });  
    10. //end  
    11.   
    12. //內(nèi)容圖片最大寬度  
    13. $(".productImg img").each( function() {  
    14. var maxwidth = 990;  
    15. if ($(this).width() > maxwidth) {  
    16. $(this).width(maxwidth);  
    17. }  
    18. });   
    19. //end  
    20.   
    21.   
    22. });  
    XML/HTML代碼
    1. <div class="pro_img2">  
    2.   <a href='此處填入鏈接地址' target='_blank'>  
    3.      <img src='http://www.ywttx.com/uploads/image/20131011/20131011105344374437.jpg'>  
    4.   </a>  
    5. </div>