Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vendor prefixes for javascript

I'm new to this world of coding. My knowledge of HTML and CSS is minimum and inexistent when it comes to Javascript.

I am working on a project for which I need to create a parallax site and each section is divided diagonally. The parallax bit is almost done but I'm struggling to make the diagonals functional on different browsers. Using a bit of code somebody else put in this forum I got to do it for Firefox but still need to make it work on the other browsers or at least Chrome and Safari. Can anyone help?

HTML

<div>
  <section><a href="#1"></a></section>
  <section><a href="#2"></a></section>
</div>

CSS

html, body, div{ height: 100%; width: 100%; padding: 0; margin: 0; }
div { overflow : hidden; position: relative;  }
section { 
height        : 500%;
background    : red; 
width         : 500%;
position      : absolute;
top           : -100%;
-moz-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
-o-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
}

section + section { 
background: #333;    
top       : 80%;
-moz-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
-o-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
} 

section a { display: block; width: 100%; height: 100%; cursor: pointer; }

JS

$(function() {

$(window).on('resize', function() {
   var h = $(document).height(),
       w = $(document).width(); 

   var angle = ((Math.atan(h/w) * 10.29577951308232));
   $('section').css("-moz-transform", "rotate(" + angle + "deg)")

})
.triggerHandler('resize');
});
like image 679
Gonzalo Fernandez Avatar asked Aug 03 '26 22:08

Gonzalo Fernandez


1 Answers

As Rob W. pointed out, jQuery will (in recent versions) add vendor prefixes for you. However, that means you shouldn't do it yourself:

$('section').css("transform", "rotate(" + angle + "deg)");

This works in both Chrome and Firefox for me: Fiddle

like image 190
Ingo Bürk Avatar answered Aug 06 '26 13:08

Ingo Bürk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!