重构的小技巧

1. CSS3对话框

 .talk{width: 100px; height: 30px; background: #ffffff; border-radius: 5px; position: absolute; left: 100px; top: 100px;}
 .talk:after{content: ""; border-width:10px 20px;   border-style:dashed solid solid dashed;   position: absolute; left: -20px; top: 17px; border-color: transparent #ffffff #ffffff transparent; transform:rotate(-40deg)}

如图



2.兼容IE6的侧边栏代码(无需再写脚本)

.sel-box{float:left; z-index:9999; position:fixed; background:#000; width:170px; height:175px; top:172px;left:50%;margin-left:500px;  _position:absolute;_top:expression(documentElement.scrollTop+172); visibility: hidden;}


3. 滑动跳转锚点(记得前提连接jq库)
$(window).bind("scroll resize", function () {
        var winWidth = $(window).width();
        var winHeight = $(window).height();
        if (winWidth > 1250 && $(window).scrollTop() > winHeight) {
        $('.sel-box').css('visibility', 'visible');
        } else {
        $('.sel-box').css('visibility', 'hidden');
        }
    });
        //锚点跳转滑动效果
    $('a[href*=#],area[href*=#]').click(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({
                        scrollTop: targetOffset
            }, 1000);
            return false;
        }
    }
    });

4.使用rem布局

  //获取屏幕宽度改变rem设置的值
   
    var CWidth = document.documentElement.clientWidth || document.body.clientWidth;
        // console.log(CWidth);
    document.documentElement.style.fontSize = (CWidth/640*20)+"px";

其中640是设计稿的宽度

5.移动端移动事件

 var startX = 0,
     startY = 0,
     moveX = 0,
     moveY = 0;
    window.addEventListener("touchstart", function(ev) {
        startX = ev.touches[0].pageX;
        startY = ev.touches[0].pageY;
    }, false);
    window.addEventListener("touchmove", function(ev) {
        ev.preventDefault(); //取消浏览器默认动作
        moveX = ev.touches[0].pageX;
        moveY = ev.touches[0].pageY;
    }, false);
    window.addEventListener("touchend", function(ev) {
        if(moveX==0){
            console.log('相同位置');
        }else{
            if (startX - moveX < -50) {
                console.log("左滑");
            }
            if (startX - moveX > 50) {
                console.log("右滑");
            }
        }
    }, false);


6.获取地址栏的参数

function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return unescape(r[2]); return null;
    }
    var nums = GetQueryString('rdm');


    //如:www.baidu.com?rdm=0; 此时0可以被nums给获取到



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值