jQuery sizing tools


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $.fn.setOuterWidth = function(px) {
  2. var width = px -
  3. parseFloat(this.css('padding-left')) -
  4. parseFloat(this.css('padding-right')) -
  5. parseFloat(this.css('border-left-width')) -
  6. parseFloat(this.css('border-right-width'))
  7. return this.css('width', width + 'px')
  8. }
  9. $.fn.getOffsetRight = function() {
  10. return Math.round(this.outerWidth() + this.offset().left)
  11. }
  12. $.fn.getOffsetBottom = function() {
  13. return Math.round(this.outerHeight() + this.offset().top)
  14. }
  15. $.fn.isChildOf = function(node) {
  16. if (node instanceof $) {
  17. node = node[0]
  18. }
  19. if (!node) {
  20. return false
  21. }
  22. var child, i
  23. for (i = 0; i < this.length; i++) {
  24. child = this[i]
  25. do {
  26. child = child.parentNode
  27. if (child == node) {
  28. return true
  29. }
  30. }
  31. while (child)
  32. }
  33. return false
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.