html5 textarea 写入换行的方法

html5 textarea 写入换行的方法

   <textarea id="fwe" class="selmiao" cols="30" rows="10"></textarea>
  $('#fwe').val('wwe\nffwe');

ps:必须用js的方法写入才可以 直接在html事先写好不行


     var miaoshu = $('#fwe').val();
        miaoshu = miaoshu.replace('\n', '||');
        miaoshu = miaoshu.replace('\n', '||');
        miaoshu = miaoshu.replace('\n', '||');
        miaoshu = miaoshu.replace('\n', '||');

读取 然后读取并看不到\n

html5 点击播放video的方法

html5 点击播放video的方法

 <video  videosrc="{$vo.shipinurl}" controls="" x5-playsinline="" playsinline="" webkit-playsinline="" poster="">
          </video>

      var videosrc=$(this).parents('.shipincontainer').find('video').attr('videosrc');
        $(this).parents('.shipincontainer').find('video').attr('src',videosrc);
        $(this).parents('.shipincontainer').find('video')[0].play();

ps:事先不能把地址src写上 不然浏览器肯定会尝试加载 会影响整体页面加载时间

html5 svg实现不规则形状图片触发事件

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>

htm5手机端实现拖动图片

htm5手机端实现拖动图片


<!doctype html>
<html>
<head>
    <title>Mobile Cookbook</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        .someElm {
            width:4rem;
            height:4rem;

            position:absolute;

        }
        .someElm1{
            left:3%;top:10%;
            background:#ccc;
        }
        .someElm2{
            left:13%;top:25%;
            background:#f00000;
        }
        .someElm3{
            left:70%;top:10%;
            background: #0B8E00;
        }
    </style>
</head>
<body>

    <div class="someElm someElm1">
    </div>
    <div class="someElm someElm2">
    </div>
    <div class="someElm someElm3">
    </div>

<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
<!-- <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>-->
<script>
     var chumodianposleft;
     var chumodianpostop;
    $('.someElm').bind('touchstart',function(e){
        var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
        /*读取选中元素的绝对定位的值*/
        var pianyi=$(this).offset();
        /*选中的地方离元素的边距*/
        chumodianposleft=touch.pageX-pianyi.left;
        chumodianpostop=touch.pageY-pianyi.top;
    })
    $('.someElm').bind('touchmove',function(e){

        var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
         /*左上角为0,0*/

        $(this).css('left',touch.pageX-chumodianposleft);
        $(this).css('top',touch.pageY-chumodianpostop);
    });
</script>
</body>
</html>

下面的来个升级版的demo 拖动元素到中间的框里面 然后元素消失

<!doctype html>
<html>
<head>
    <title>Mobile Cookbook</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        .someElm {
            width:4rem;
            height:4rem;

            position:absolute;

        }
        .someElm1{
            left:3%;top:10%;
            background:#ccc;
        }
        .someElm2{
            left:13%;top:25%;
            background:#f00000;
        }
        .someElm3{
            left:70%;top:10%;
            background: #0B8E00;
        }

        .gudingceshi {
            width:6rem;
            height:6rem;
            position:absolute;
            left: 37%;
            top: 47%;
            background: #000;
        }
    </style>
</head>
<body>

    <div class="someElm someElm1">
    </div>
    <div class="someElm someElm2">
    </div>
    <div class="someElm someElm3">
    </div>
    <div class="gudingceshi">
    </div>

<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
<!-- <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>-->
<script>

     var chumodianposleft;
     var chumodianpostop;
    $('.someElm').bind('touchstart',function(e){
        var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
        /*读取选中元素的绝对定位的值*/
        var pianyi=$(this).offset();
        /*选中的地方离元素的边距*/
        chumodianposleft=touch.pageX-pianyi.left;
        chumodianpostop=touch.pageY-pianyi.top;
    })
    $('.someElm').bind('touchmove',function(e){

        var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];

         /*左上角为0,0*/
        var x2=$('.gudingceshi').offset().left;
        var y2=$('.gudingceshi').offset().top;
        var w=$('.gudingceshi').width();
        var h=$('.gudingceshi').height();
        var ispengzhuang=isCollsion(touch.pageX,touch.pageY,x2,y2,w,h);
        if(ispengzhuang){
            $(this).remove();
        }

        $(this).css('left',touch.pageX-chumodianposleft);
        $(this).css('top',touch.pageY-chumodianpostop);
    });
</script>

<script>


    /**
     *
     * @param x1 点
     * @param y1 点
     * @param x2 矩形view x
     * @param y2 矩形view y
     * @param w  矩形view 宽
     * @param h  矩形view 高
     * @return
     */
    function isCollsion(x1,y1,x2,y2,w,h) {
        if (x1 >= x2 && x1 <= x2 + w && y1 >= y2 && y1 <= y2 + h) {
            console.log('碰撞');
            return true;
        }
        console.log('没碰撞');
        return false;
    }
</script>
</body>
</html>

html5获取自己定位的方法

html5获取自己定位的方法
直接用高德地图api 不要用百度地图api 不准确

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>浏览器定位</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript"
            src="http://webapi.amap.com/maps?v=1.3&key=00955dce4bad4be3ec81058776e0e307"></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<body>

<div style="width:30px; height:30px; background: #000; position: absolute;left:10px; top:10px;z-index: 9999" class="dss" onclick="getdingwei();"></div>
  <div id="result"></div>
<div id='container' style="display: none"></div>
<div id="tip"></div>
<script type="text/javascript">

    function regeocoder(lnglatXY) {  //逆地理编码
        var geocoder = new AMap.Geocoder({
            radius: 1000,
            extensions: "all"
        });
        geocoder.getAddress(lnglatXY, function(status, result) {
            if (status === 'complete' && result.info === 'OK') {
                geocoder_CallBack(result);
            }
        });
        var marker = new AMap.Marker({  //加点
            map: map,
            position: lnglatXY
        });
    }
    function geocoder_CallBack(data) {
        var address = data.regeocode.formattedAddress; //返回地址描述
        document.getElementById("result").innerHTML = address;
    }
function getdingwei() {
    map.plugin('AMap.Geolocation', function() {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位,默认:true
            timeout: 10000,          //超过10秒后停止定位,默认:无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
            buttonPosition:'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
    });
}

    /***************************************
     由于Chrome、IOS10等已不再支持非安全域的浏览器定位请求,为保证定位成功率和精度,请尽快升级您的站点到HTTPS。
     ***************************************/
    var map, geolocation;
    //加载地图,调用浏览器定位服务
    map = new AMap.Map('container', {
        resizeEnable: true
    });

    //解析定位结果
    function onComplete(data) {
        lnglatXY = [data.position.getLng(), data.position.getLat()]; //已知点坐标
        regeocoder(lnglatXY);
        var str=['定位成功'];
        str.push('经度:' + data.position.getLng());
        str.push('纬度:' + data.position.getLat());
        if(data.accuracy){
            str.push('精度:' + data.accuracy + ' 米');
        }//如为IP精确定位结果则没有精度信息
        str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));
        document.getElementById('tip').innerHTML = str.join('<br>');
    }
    //解析定位错误信息
    function onError(data) {
        document.getElementById('tip').innerHTML = '定位失败';
    }
</script>
</body>
</html>

直接点黑色方块就可以获取定位 pc和浏览器都支持
ps:别用谷歌浏览器的那个模拟手机端的机制测试 会定位失败

移动端实现裁剪图片生成base64图片(可缩放)

移动端实现裁剪图片生成base64图片(可缩放)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>{$title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <!-- Link Swiper's CSS -->
    <include file="commonheader" />
    <link href="/croppermaster/dist/cropper.css" rel="stylesheet">
    <style type="text/css">

    </style>
</head>

<body>
    <div class="box" style="width:100%;height:100%; position: absolute;left:0px; top:0px; z-index: 9999;background: #000;">
        <img  class="image" src="/croppermaster/dist/1.jpg">
  <div class="caijian" style="width:80px; height:30px; line-height: 30px; text-align: center; background: #0ac2ff; border-radius:10px; position: absolute;right:30px; bottom: 30px; color: #FFF;">确定</div>
    <div class="quxiaocaijian" style="width:80px; height:30px; line-height: 30px; text-align: center; background: #0ac2ff; border-radius:10px; position: absolute;left:30px; bottom: 30px; color: #FFF;">取消</div>
    <div style="width:100%; height: auto;overflow: hidden;">
        <img style="width:30%;" class="showpic" src="" alt="">
    </div>        
    </div>
  
    <include file="commonfooter" />
    <script src="/croppermaster/dist/cropper.js"></script>
    <script type="text/javascript">
    $(function() {
 $('.image').cropper({
            aspectRatio: 9 / 12,
            viewMode: 1,
            crop: function(e) {
                // console.log(e);
            }
        });

         //裁剪完压缩方法
        $('.caijian').on('click', function() {
              var result = $('.caijianpic').cropper("getCroppedCanvas", {
            width: 750,
            height: 1000
        });

            var base64img = result.toDataURL("image/jpg");
            $('.showpic').attr('src', base64img);
        })
        $('.quxiaocaijian').on('click', function() {
            $('.image').cropper("destroy")
        })

    })
    </script>
</body>

</html>

ps:这个案例是裁剪中状态的