Js achieves 360-degree rotation of images and 360-degree js Images

Source: Internet
Author: User

Js achieves 360-degree rotation of images and 360-degree js Images

Overview

This is a simple result, but it is a problem of thinking.

Effect:

Ideas

The rotation effect is to display different images based on the moving distance of the mouse, forming a visual difference, as if it is being rotated

Because the effect is based on the moving distance of the mouse, that is, the moving pixel value. By default, the image rotates too fast when you move the mouse. Therefore, we need to move the mouse 15 minutes away to reduce the image rotation speed.

var l = parseInt(-x/15);

One problem is that when the mouse moves to the left, the moving distance is negative. To correctly display the image, you must process the negative value. For example, in-1, the last image is 72 (72 images in total ). -100: 44th images must be displayed. However, since the image name starts from 1, rather than from 0, you must add 1 at the end.

var l = parseInt(-x/15);  if(l > 0){   l = l%72+1;  }else{   l = (l + -72*(Math.floor(l/72))) + 1;  }

Code

<style> html,body {height:100%;} body {margin:0;} img{ width: 640px; height: 378px; position: absolute; left: 50% top: 50%; margin-top:120px;  margin-left:320px; } </style> <script> window.onload = function(){ var x = 0; var oImg = document.getElementById('img1'); document.onmousedown = function(ev){  var ev = ev || enent;  var disX = ev.clientX - x;  document.onmousemove = function(ev){  var ev = ev || event;  x = ev.clientX - disX;  var l = parseInt(-x/15);  if(l > 0){   l = l%72+1;  }else{   l = (l + -72*(Math.floor(l/72))) + 1;  }  oImg.src = "img/Seq_v04_640x378_"+ l +".jpg"  return false;  };  document.onmouseup = function(){  document.onmouseup = null;  document.onmousemove = null;  }  return false; } } </script>

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Related Article

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.