You have so many hacks, what should you do_html/css_WEB-ITnose
When we operate css styles through javascript, if we stay at the css2 stage, we will find that it is not very difficult to operate. Although there are some browser compatibility issues, by encapsulating our own functions, we can not only set styles but also obtain styles. However, what will happen if javascript encounters css3?
We know that although CSS3 currently appears in various browsers, it has not yet been officially released as a set of specifications. Therefore, each browser has different support for CSS3 attributes. Hence the term "css Hack". Great, why? Because through css Hack we can be compatible with various browsers at the css level, and there is no need to borrow javascript to achieve it. But the five major browsers have their own Hack headers (Safari and chrome are: webkit. IE is: ms. Opera is: o. Firefox is: moz). This also creates a certain degree of code redundancy. And when we control css3 attributes through js, another problem arises.
The problem that arises this time is not difficult. In the final analysis, it is a problem of code redundancy (because we have to set styles for 4 mainstream kernels respectively), so let’s solve this problem through functions:
1 function setHack(ele,attr) { 2 //利用for-in循环遍历attr里面的属性 3 for (var i in attr){ 4 var newi = i; 5 //遍历是不是有- 6 if(newi.indexOf("-")>0) { 7 var num = newi.indexOf("-"); 8 newi = newi.replace(newi.substr(num,2),newi.substr(num+1,1).toUpperCase()); 9 }10 //常规的设置属性的方式11 ele.style[newi] = attr[i];12 newi = newi.replace(newi.charAt(0),newi.charAt(0).toUpperCase());13 ele.style["webkit" + newi] = attr[i];14 ele.style["moz" + newi] = attr[i];15 ele.style["ms" + newi] = attr[i];16 ele.style["o" + newi] = attr[i];17 }18 }
Function description: The setHack function has two parameters: ele represents which element you want to set attributes for, attr is a json format that contains the attributes and attribute values you set. , such as {"transform":"rotate(20deg)","transform-origin":"120px 120px"}. The if judgment in the code is mainly to change the "-" in the attribute into the format of uppercase letters. The latter is mainly about adding the core part of the Hack header.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to distinguish between closing tabs and closing entire browser using JavaScript on your browser? During the daily use of the browser, users may...
