Tips for refactoring

Source: Internet
Author: User

1. CSS3 dialog Box

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. compatible with IE6 Sidebar code (no more scripting)

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. slide jump Anchor Point ( Remember the premise connection JQ library)
$ (Window). bind ("Scroll resize", function () {var winwi        DTH = $ (window). width ();        var winheight = $ (window). Height (); if (Winwidth > 1250 && $ (window). scrolltop () > Winheight) {$ ('. Sel-box '). CSS (' visibility ', ' visible '        );        } else {$ ('. Sel-box '). CSS (' visibility ', ' hidden ');        }    }); Anchor point Jump Slide effect $ (' a[href*=#],area[href*=#] '). Click (function () {if (Location.pathname.replace (/^\//, ') = = = This.pat            Hname.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. Using the REM layout

  Get screen width Change the value of REM settings       var cwidth = Document.documentElement.clientWidth | | document.body.clientWidth;        Console.log (cwidth);    Document.documentElement.style.fontSize = (cwidth/640*20) + "px";

Where 640 is the width of the design manuscript

5. Mobile-Move Events

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 ();//Cancel Browser default action        MoveX = ev.touches[0 ].pagex;        Movey = Ev.touches[0].pagey;    }, False);    Window.addeventlistener ("Touchend", function (EV) {        if (movex==0) {            console.log (' same position ');        } else{            if (Startx-movex < -50) {                Console.log ("left Slide");            }            if (Startx-movex >) {                console.log ("right-sliding");}}    }, False);


6. Get the parameters of the address bar

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 ');    such as: www.baidu.com?rdm=0; At this point 0 can be obtained by nums



Tips for refactoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.