Blogger Information
Blog 20
fans 0
comment 0
visits 19647
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML svg自适应写法和SVG实现不规则形状图片触发事件
大鱼
Original
1090 people have browsed it
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title></head><body>
    <div style="width:30%; height:3.6rem;">
     <svg width="100%" height="100%" viewBox="0,0,40,30" style="border:1px solid #cd0000;">
         <rect x="0" y="0" width="40" height="30" fill="#cd0000"/>
    </svg>
    </div>
    <script src="/moban/js/jquery.min.js"></script>
    <script type="text/javascript">
   (function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        /*如果屏幕尺寸发生了变化就会立即更新*/
        recalc = function() {
            /*     var clientWidth = docEl.clientWidth;*/
            var clientWidth = parseInt($('body').width());
            if (!clientWidth) return;
            docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
        };
    if (!doc.addEventListener) return;
    /*如果窗口改变了大小 手机旋转了都会重新修改font-size属性*/
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);})(document, window);    	
    $(function() {
        $('.dds').on('click', function() {
            $(this).attr('fill', 'green');
        })
    })
 

    </script></body></html>
    
    html5 svg实现不规则形状图片触发事件
    
    <!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title></head><body><svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"  class="dds" /></svg><script src="/moban/js/jquery.min.js"></script><script type="text/javascript">
    $(function(){
        $('.dds').on('click',function(){
            $(this).attr('fill','green');
        })
    })</script></body></html>



原文地址:http://newmiracle.cn/?m=201803

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post