What is the commonly used encapsulation method in the front end of web
This article introduces the relevant knowledge of "what are the commonly used encapsulation methods in the front end of web?" in the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Magnifying glass
/ / execute after the page is loaded
_ window.onload=function () {
VaroDemo=document.getElementById ('demo')
VaroMark=document.getElementById ('mark')
VarFloatBox=document.getElementById ('float-box')
VarSmallBox=document.getElementById ("small-box")
VarbigBox=document.getElementById ('big-box')
VarbigImg=bigBox.getElementsByTagName ('img') [0]
OMark.onmouseover=function () {
FloatBox.style.display= "block"
BigBox.style.display= "block"
}
OMark.onmouseout=function () {
FloatBox.style.display= "none"
BigBox.style.display= "none"
}
OMark.onmousemove=function (ev) {
Varev=ev | | window.event
Varleft=ev.clientX-oDemo.offsetLeft-SmallBox.offsetLeft-FloatBox.offsetWidth/2
Vartop=ev.clientY-oDemo.offsetTop-SmallBox.offsetTop-FloatBox.offsetHeight/2
If (left=oMark.offsetWidth-FloatBox.offsetWidth-10) {
Left=oMark.offsetWidth-FloatBox.offsetWidth
}
If (top=oMark.offsetHeight-FloatBox.offsetHeight-10) {
Top=oMark.offsetHeight-FloatBox.offsetHeight
}
FloatBox.style.left=left+ "px"
FloatBox.style.top=top+ "px"
VarscaleX=left/ (oMark.offsetWidth-FloatBox.offsetWidth)
VarscaleY=top/ (oMark.offsetHeight-FloatBox.offsetHeight)
BigImg.style.left=-scaleX* (bigImg.offsetWidth-bigBox.offsetWidth) + "px"
BigImg.style.top=-scaleY* (bigImg.offsetHeight-bigBox.offsetHeight) + "px"
}
}
2 、 JSONP
Functionfn1 (data) {
Varhtml=''
VaroUl=document.getElementsByTagName ('ul') [0]
Console.log (data)
If (DATA. Totalcake colors Muffle 1) {
For (vari=0;i