Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var parallaxMouse = function(el, coeff, direction) {
  2. $(window).bind('mousemove', function(e) {
  3. parallaxScroll(e);
  4. });
  5.  
  6. function parallaxScroll(e) {
  7. $(el).each(function() {
  8. var container = $('body'),
  9. containerWidth = container.width(),
  10. containerHeight = container.height(),
  11. mouseXCord = event.pageX,
  12. mouseYCord = event.pageY,
  13. shiftX = containerWidth/2 - mouseXCord,
  14. shiftY = containerHeight/2 - mouseYCord,
  15. transformString;
  16.  
  17. if(direction === "x") {
  18. transformString = 'transform: translateX(' + shiftX / (coeff*10) + '%)';
  19. }
  20.  
  21. if(direction === "y") {
  22. transformString = 'transform: translateY(' + shiftY / (coeff*10) + '%)';
  23. }
  24.  
  25. if(direction === "xy") {
  26. transformString = 'transform: translate(' + shiftX / (coeff*10) + '%, ' + shiftY / (coeff*10) + '%)';
  27. }
  28.  
  29. this.style = transformString;
  30. })
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement