This time I will bring you Javascript to create an imitation Apple touch screen effect. What are the precautions for using Javascript to create an imitation Apple touch screen effect? The following is a practical case, let’s take a look.
Javascript to make imitation apple white spots
Just introduce the code directly into the page
The code has some redundant parts, interested friends can modify it themselves
If there are any BUGs Remember to comment and tell me
var new_element_N=document.createElement("style"); new_element_N.innerHTML = '#drager {' + ' position: fixed;' + ' width: 35px;' + ' height: 35px;' + ' background-color: rgba(0, 0, 0, 0.2);' + ' z-index: 10000;' + ' cursor: pointer;' + ' top: 0px;' + ' left: 0px;' + ' border-radius: 30%;' + ' padding: 6px;' + ' }' + ' ' + ' #drager>div {' + ' border-radius: 50%;' + ' width: 100%;' + ' height: 100%;' + ' background-color: rgba(0, 0, 0, 0.3);' + ' transition: all 0.2s;' + ' -webkit-transition: all 0.2s;' + ' -moz-transition: all 0.2s;' + ' -o-transition: all 0.2s;' + ' }' + ' #drager:hover>div{' + ' background-color: rgba(0, 0, 0, 0.6);' + ' } '; document.body.appendChild(new_element_N); new_element_N=document.createElement('div'); new_element_N.setAttribute("id","drager"); new_element_N.style.top="100px"; new_element_N.style.left="100px"; new_element_N.innerHTML = ' <div></div>' ; document.body.appendChild(new_element_N); // // var posX; var posY; var screenWidth =document.documentElement.clientWidth; var screenHeight = document.documentElement.clientHeight; var fdiv = document.getElementById("drager"); fdiv.onmousedown=function(e) { screenWidth =document.documentElement.clientWidth; screenHeight = document.documentElement.clientHeight; if(!e){ e = window.event; } //IE posX = e.clientX - parseInt(fdiv.style.left); posY = e.clientY - parseInt(fdiv.style.top); document.onmousemove = mousemove; } document.onmouseup = function()//释放时自动贴到最近位置 { document.onmousemove = null; if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenHeight/2)){//在上半部分 if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)){//在左半部分 if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)){//靠近上方 fdiv.style.top="0px"; }else{//靠近左边 fdiv.style.left="0px"; } }else{//在右半部分 if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ){//靠近上方 fdiv.style.top="0px"; }else{//靠近右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; } } }else{ //下半部分 if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)){//在左半部分 if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)){//靠近下方 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{//靠近左边 fdiv.style.left="0px"; } }else{//在右半部分 if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ){//靠近上方 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{//靠近右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; } } } } function mousemove(ev) { if(ev==null){ ev = window.event;}//IE if((ev.clientY - posY)<=0){//超过顶部 fdiv.style.top="0px"; }else if((ev.clientY - posY) >(screenHeight-parseInt(fdiv.clientHeight))){//超过底部 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{ fdiv.style.top = (ev.clientY - posY) + "px"; } if((ev.clientX- posX)<=0){//超过左边 fdiv.style.left="0px"; }else if((ev.clientX - posX) >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; }else{ fdiv.style.left = (ev.clientX - posX) + "px"; } // console.log( posX +" "+ fdiv.style.left); } window.onload = window.onresize = function() { //窗口大小改变事件 screenWidth =document.documentElement.clientWidth; screenHeight = document.documentElement.clientHeight; if( (parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight))>screenHeight){//窗口改变适应超出的部分 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; } if( (parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth))>screenWidth){//窗口改变适应超出的部分 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; } document.onmouseup.apply() }; fdiv.addEventListener('touchstart', fdiv.onmousedown, false); fdiv.addEventListener('touchmove', function(event) { // 如果这个元素的位置内只有一个手指的话 if (event.targetTouches.length == 1) { event.preventDefault();// 阻止浏览器默认事件,重要 var touch = event.targetTouches[0]; if((touch.pageY)<=0){//超过顶部 fdiv.style.top="0px"; }else if(touch.pageY>(screenHeight-parseInt(fdiv.clientHeight))){//超过底部 fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px"; }else{ fdiv.style.top = (touch.pageY-parseInt(fdiv.clientHeight)/2) + "px"; } if(touch.pageX<=0){//超过左边 fdiv.style.left="0px"; }else if( touch.pageX >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边 fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px"; }else{ fdiv.style.left = (touch.pageX-parseInt(fdiv.clientWidth)/2) + "px"; } } }, false); fdiv.addEventListener('touchend', document.onmouseup , false); fdiv.ondblclick=function(){//双击事件可能在手机端浏览器会与网页缩放事件冲突 alert("发挥你们的想象力吧"); }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
Simple image click upload function
Can JS capture the tagged video thumbnail of a video?
The above is the detailed content of Javascript creates imitation Apple touch screen effect. For more information, please follow other related articles on the PHP Chinese website!

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment
