Giter Club home page Giter Club logo

jquery.fixborderbox.js's Introduction

jQuery Fix box-sizing: border-box Width and Height Animations

In jQuery 1.7.x and previous the .css('width') and .css('height') will deduct any padding and margins. But the CSS property box-sizing: border-box means these should not be deducted. The upshot is if you've ever tried to animate width or height on an element with box-sizing: border-box you'll notice all kinds of weird jerkiness.

Take this example which tries to add 50px to the width of a border-box which has 20px padding and 1px border:

$('.border-box').animate(
    { width: parseInt($('.border-box').css('width')) + 50 }
);

The box will appear to jerkily narrow then expand. If the animation was ging the other way, wide to narrow, it would appear to skip the first part of the animation.

This script will allow you to workaround that by using a pseudo CSS property bbwidth:

$('.border-box').animate(
    { bbwidth: parseInt($('.border-box').css('bbwidth')) + 50 }
);

This is fixed in jQuery 1.8.x and above to work as expected, although the width() function has not changed and still returns the width without border and padding.

MIT License.

jquery.fixborderbox.js's People

Contributors

paulwib avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.