scissor.js 774 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * scissor.js
  3. *
  4. * Copyright (C) 2012 Emmanuel Garcia
  5. * MIT Licensed
  6. *
  7. * Cuts paper for you! and cardboard too ;)
  8. **/
  9. (function($) {
  10. 'use strict';
  11. $.extend($.fn, {
  12. scissor: function() {
  13. this.each(function() {
  14. var element = $(this),
  15. pageProperties = {
  16. width: element.width()/2,
  17. height: element.height(),
  18. overflow: 'hidden'
  19. },
  20. newElement = element.clone(true);
  21. var leftPage = $('<div />', {css: pageProperties}),
  22. rightPage = $('<div />', {css: pageProperties});
  23. element.after(leftPage);
  24. leftPage.after(rightPage);
  25. element.css({
  26. marginLeft: 0
  27. }).appendTo(leftPage);
  28. newElement.css({
  29. marginLeft: -pageProperties.width
  30. }).appendTo(rightPage);
  31. });
  32. return this;
  33. }
  34. });
  35. })(jQuery);