Several useful JQuery techniques and JQuery useful techniques

Source: Internet
Author: User

Several useful JQuery techniques and JQuery useful techniques

JQuery code

/* Open the link in the new window: JQuery filter attr * disable the mouse to pop up the right-click menu: DOM contextmenu * back to the top of the page: DOM scrollTo * dynamic change Css style sheet: JQuery filter Element Attribute * adjust the page font size: Css html.css parseFloat * // determine whether DOM loading is complete $ (document ). the href attribute of ready (function () {/* link starts with http and opens the link in the new window * // ^ filter. properties: start with a specific string $ ("a [href ^ = 'HTTP ']"). attr ("target", "_ blank");/* Right-click prohibited * // The contextmenu of DOM is the right-click menu $ (document ). bind ("contextmenu", function (e) {alert (( "No right-clicking! "); // Do not run down, that is, the right-click menu cannot return false ;}); /* return to the top of the page * // id = "top" element's click Event trigger $ ('# top '). click (function () {// return to the top of the page $ (document ). scrollTo (0,500 );}); /* dynamically change the css style table of the page * // use the href value of the page link to replace the href attribute value of the link tag $ ("a.css Swap "). click (function () {$ ("link [rel = stylesheet]"). attr ("href", $ (this ). attr ("rel");});/* enlarge, zoom in, or restore the page font size * // obtain the font size, the font-size var originalFontSize = $ ("html" ).css ("font-size") is defined under the html Tag; // restore the default font size $ (". resetFont "). click (function () {$ ("html" ).css ("font-size", originalFontSize); // JavaScript does not run return false;}); // increase the font, the class of an element is defined as increaseFont $ (". increaseFont "). click (function () {// get the current font size suffix px, pt, pc var currentFontSize =$ ("html" ).css ("font-size "); // get the current font size. Convert parseFloat () to the float type to remove the suffix var currentFontSizeNumber = parseFloat (currentFontSize); // the newly defined font size var newFontSize = currentFontSizeNumber * 1.1; // rewrite the style sheet $ ("html" ).css ("font-size", newFontSize); // do not run return false in JavaScript;}); // reduce the font, the class of an element is defined as decreaseFont $ (". decreaseFont "). click (function () {// get the current font size suffix px, pt, pc var currentFontSize =$ ("html" ).css ("font-size "); // get the current font size. Convert parseFloat () to the float type to remove the suffix var currentFontSizeNumber = parseFloat (currentFontSize); // redefine the font size var newFontSize = currentFontSizeNumber * 0.9; // rewrite the style sheet $ ("html" ).css ("font-size", newFontSize); // do not run return false ;});});

 

Html code:

<! DOCTYPE html> <meta charset = "UTF-8"/> 

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.