Saturday, 8 February 2014

360 degree rotation

Leave a Comment

 Many times you would have seen 360 degree roation of some objects on web page to display its all around dimensions close to reality. Here, is the code snippet that can be used for achieving the same visual effect. We have to take enough number of images of same dimensions and keem them at same location. Name these images in an order say, from 1 to 35.

Use the HTML Code below:

  1. <link href="styles/mystyle.css" rel="stylesheet">  
  2. <script src="main.js"></script>  
  3.   
  4.   
  5. <div id="mydiv">  
  6.  <img src="images/1.jpg">  
  7. </div>  
Use the CSS Code below:
  1. body  
  2. {  
  3.  padding: 0px;  
  4.  margin: 0px;   
  5. }  
  6. div  
  7. {  
  8.    
  9.  width: 210px;  
  10.    
  11. }  
Create a "main.js" javascript file and Use the Code below:
  1. window.onload = init;  
  2.   
  3. var mydiv;  
  4. var down = false;  
  5. var selectedPoint = 0;  
  6. var file = 1;  
  7. function init(e)  
  8. {  
  9.  mydiv = document.getElementById("mydiv");  
  10.  mydiv.addEventListener("mousedown",onDown);  
  11.  mydiv.addEventListener("mouseup",onUp);  
  12.  mydiv.addEventListener("mousemove",onMove);  
  13.  mydiv.addEventListener("mouseout",onOut);  
  14. }  
  15.   
  16. function onOut(e)  
  17. {  
  18.  e.preventDefault();  
  19.  down = false;  
  20. }  
  21.   
  22. function onDown(e)  
  23. {  
  24.  selectedPoint = e.clientX;  
  25.  e.preventDefault();  
  26.  down = true;  
  27.    
  28. }  
  29. function onUp(e)  
  30. {  
  31.  e.preventDefault();  
  32.  down = false;  
  33. }  
  34.   
  35. function onMove(e)  
  36. {  
  37.  if(down)  
  38.  {  
  39.   if(selectedPoint > e.clientX)  
  40.   {  
  41.    //console.log(selectedPoint,e.clientX);  
  42.    nextImage();     
  43.   }else if(selectedPoint < e.clientX)  
  44.   {  
  45.    //console.log(selectedPoint,e.clientX);  
  46.    prevImage();  
  47.   }  
  48.   selectedPoint = e.clientX;  
  49.  }  
  50. }  
  51.   
  52. function nextImage()  
  53. {  
  54.  if(file==35) file = 1;  
  55.  mydiv.children[0].setAttribute("src","images/"+file+".jpg");  
  56.  file++;  
  57. }  
  58. function prevImage()  
  59. {  
  60.  if(file == 0) file = 35;  
  61.  mydiv.children[0].setAttribute("src","images/"+file+".jpg");  
  62.  file--;  
  63. }  
I hope you found this tutorial to be of help and useful. Please leave a message in the comment section below, should you need further assistance or advice.
 
 
      
      
      
      
    
Read More...

Creating reflection on images using CSS3 and HTML

Leave a Comment

In most of the websites we will see reflection graphics on images like below. But most of the web developers and web designers are using images (Photoshop images) to achieve the below effect.
Photoshop reflection (Using Photoshop)

But now using CSS3 we can achieve the above reflection effect easily without using tools like Photoshop.
CSS3 reflection (DEMO)


Use the below code to achieve the same.
Use the below CSS code.
  1. <style>  
  2.    .product  
  3.    {  
  4.     float:left;  
  5.     width:150px;  
  6.       
  7.    }  
  8.    .product img  
  9.    {  
  10.     width:100px;  
  11.    }  
  12.    .shadow {   
  13.     width:100%;  
  14.     height:100%;  
  15.     position:absolute; top:0px; left:0px; ;   
  16.     background-image: -moz-linear-gradient( center bottom, rgb(255,255,255) 60%, rgba(255,255,255,0) 75%);   
  17.     background-image:   -o-linear-gradient( rgba(255,255,255,0) 25%, rgb(255,255,255) 40%);   
  18.     background-image:     -webkit-gradient( linear, left bottom, left top, color-stop(0.60, rgb(255,255,255)), color-stop(0.75, rgba(255,255,255,0)));   
  19.     filter: progid:DXImageTransform.Microsoft.Gradient( gradientType=0, startColor=0, EndColorStr=#ffffff);   
  20.    }   
  21.    .reflection   
  22.    {  
  23.     position:relative;   
  24.     height:200px;  
  25.     overflow:hidden;  
  26.    }  
  27.      
  28.    .reflection img  
  29.    {  
  30.     -webkit-transform: scaleY(-1);  
  31.     opacity:0.1;  
  32.       
  33.    }  
  34.   </style>  

Use the below HTML code.
  1. <div class="product">  
  2.   
  3.    <img src="m1.jpg">  
  4.   
  5.    <div class="reflection">  
  6.   
  7.     <img src="m1.jpg">  
  8.   
  9.     <div class="shadow"></div>  
  10.   
  11.    </div>  
  12.   
  13.   </div>  
  14.   
  15.   <div class="product">  
  16.   
  17.    <img src="m2.jpg">  
  18.   
  19.    <div class="reflection">  
  20.   
  21.     <img src="m2.jpg">  
  22.   
  23.     <div class="shadow"></div>  
  24.   
  25.    </div>  
  26.   
  27.   </div>  
  28.   
  29.   <div class="product">  
  30.   
  31.    <img src="m3.jpg">  
  32.   
  33.    <div class="reflection">  
  34.   
  35.     <img src="m3.jpg">  
  36.   
  37.     <div class="shadow"></div>  
  38.   
  39.    </div>  
  40.   
  41.   </div> 
Read More...