


Javascript implements the photo wall code for dragging and clicking photos to the top_javascript skills
Demo picture
styles.css
*{ /*清空所有元素默认的外边距和内边距*/ } .photo_wall{ background:url(bg.jpg); /*定义照片墙的默认背景*/ background-size:cover; /*使照片墙的背景填充照片墙*/ width:1200px; /*设置照片墙的宽高*/ height:500px; margin:40px auto; /*设置照片墙的外边距*/ display:-webkit-box; /*使用CSS3的盒模型之流式布局*/ display:-moz-box; display:box; -webkit-box-align:center; /*定义盒模型内部元素在垂直方向上居于中间位置*/ -moz-box-align:center; box-align:center; -webkit-box-pack:center; /*定义盒模型内部元素在水平方向上居于中间位置*/ -moz-box-pack:center; box-pack:center; } .photo_wall .photo_frame{ text-align:center; /*照片内的文字都是居中显示*/ padding:10px 10px 30px 10px; /*定义照片的内补白*/ background-color:#f2eada; /*设置照片的背景颜色*/ font-size:.8em; /*照片内文字的大小*/ box-shadow:.2em .2em .8em #130c0e; /*给照片添加阴影效果,富有立体感*/ } .photo_frame p{ margin-top:10px; /*设置照片内显示文字段落的外上边距*/ } #photo01{ position:fixed;top:90px;left:50px; -webkit-transform-origin:right bottom; /*定义照片1的旋转基点为 右下角*/ -moz-transform-origin:right bottom; transform-origin:right bottom; -webkit-transform:rotate(10deg); /*以基点为轴,在2D空间内顺时针旋转10度*/ -moz-transform:rotate(10deg); -o-transform:rotate(10deg); transform:rotate(10deg); position:absolute; } #photo02{ position:fixed;top:100px;left:300px; -webkit-transform-origin:right bottom; /*定义照片2的旋转基点为 右下角*/ -moz-transform-origin:right bottom; transform-origin:right bottom; -webkit-transform:rotate(-20deg); /*以基点为轴,在2D空间内逆时针旋转20度*/ -moz-transform:rotate(-20deg); -o-transform:rotate(-20deg); transform:rotate(-20deg); position:absolute; } #photo03{ position:fixed;top:80px;left:750px; -webkit-transform-origin:left top; /*定义照片3的旋转基点为 左上角*/ -moz-transform-origin:left top; transform-origin:left top; -webkit-transform:rotate(40deg); /*以基点为轴,在2D空间内顺时针旋转40度*/ -moz-transform:rotate(40deg); -o-transform:rotate(40deg); transform:rotate(40deg); position:absolute; } #vedio1{ position:fixed;top:250px;left:950px; -webkit-transform-origin:right top; /*定义照片3的旋转基点为 左上角*/ -moz-transform-origin:right top; transform-origin:right top; -webkit-transform:rotate(-100deg); /*以基点为轴,在2D空间内顺时针旋转40度*/ -moz-transform:rotate(50deg); -o-transform:rotate(-50deg); transform:rotate(50deg); position:absolute; } div{cursor:move;} #top { right:0;top:0; width:100px; height:100%; position:fixed; padding:10px; text-align:center; font-weight:bold; background:#f2eada; opacity:0.9; }
drag.js
var zIndex = 1; window.onload = function () { var x=document.getElementsByName("photo"); for(var i=0;i<x.length;i++) { drag(x[i]); //alter(x[i].value); } //var oDrag1 = document.getElementById("photo01"); //var oDrag2 = document.getElementById("photo02"); //var oDrag3 = document.getElementById("photo03"); //var oDrag4 = document.getElementById("vedio1"); //drag(oDrag1); //drag(oDrag2); //drag(oDrag3); //drag(oDrag4); }; var cengshu=0; function drag(oDrag) { var disX = dixY = 0; oDrag.onmousedown = function (event) { var event = event || window.event; disX = event.clientX - this.offsetLeft; disY = event.clientY - this.offsetTop; oDrag.style.position='fixed'; oDrag.style.zIndex=cengshu++; //var oTemp = document.createElement("div"); //oTemp["id"] = "temp"; //oTemp.style.left = this.currentStyle ? this.currentStyle["left"] : getComputedStyle(this, null)["left"]; //oTemp.style.top = this.currentStyle ? this.currentStyle["top"] : getComputedStyle(this, null)["top"]; //oTemp.style.zIndex = zIndex++; //document.body.appendChild(oTemp); document.onmousemove = function (event) { var event = event || window.event; var iL = event.clientX - disX; var iT = event.clientY - disY; var maxL = document.documentElement.clientWidth - oDrag.offsetWidth; var maxT = document.documentElement.clientHeight - oDrag.offsetHeight iL <= 0 && (iL = 0); iT <= 0 && (iT = 0); iL >= maxL && (iL = maxL); iT >= maxT && (iT = maxT); oDrag.style.left = iL + "px"; oDrag.style.top = iT + "px"; return false; }; document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; oDrag.style.left = oTemp.style.left; oDrag.style.top = oTemp.style.top; oDrag.style.zIndex = oTemp.style.zIndex; document.body.removeChild(oTemp); oDrag.releaseCapture && oDrag.releaseCapture() }; this.setCapture && this.setCapture(); return false } }
picwall.html
<!DOCTYPE html> <html> <head> <style> div { cursor: move; } </style> <link href="styles.css" rel="stylesheet"> <script type="text/javascript" src="drag.js"></script> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body class="photo_wall"> <div name = "photo" class="photo_frame" id="photo01" name="dr"> <img src="30554.jpg" width="350" height="200" alt="fuck you"> <p> 面对两侧金色的树木,内心莫名的喜悦!</p> <p> 作者: 纤上陌</p> </div> <div name = "photo" class="photo_frame" id="photo02" name="dr"> <img src="30774.jpg" width="350" height="200" alt="fuck you"> <p> 很遗憾两颗心画在了沙滩上</p> <p> 作者: 她留我走</p> </div> <div name = "photo" class="photo_frame" id="photo03" name="dr"> <img src="30729.jpg" width="350" height="200" alt="fuck you"> <p> 野花也要精彩</p> <p> 作者: Love&Peace</p> </div> <div name = "photo" class="photo_frame" id="vedio1" name="dr"> <video src="VID_20141106_145936.mp4" controls="controls" width="350" height="200" alt="fuck you">您的浏览器不支持 video 标签。</video> <p>嘉和秋季运动会</p> <p>作者:忽左忽右</p> </div> </body> </html>
Pictures used
The above is the entire content of this article. I hope it will be helpful to everyone to become proficient in javascript.

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

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
