Javascript - Changing border-width without moving surrounding elements.

前端 未结 8 1574
萌比男神i
萌比男神i 2021-02-14 09:43

I have the following HTML:

Hover:


8条回答
  •  没有蜡笔的小新
    2021-02-14 10:16

    Decrease the width by two times the border increase ..

     $('.Size').hover(
      function() {
          var width = parseInt($(this).css('width'));
          $(this).css('borderWidth', '5px').css({width:width-8});
      },
      function() {
          var width = parseInt($(this).css('width'));
        $(this).css('borderWidth', '1px').css({width:width+8});
      })
    

    have a look at http://jsfiddle.net/rBrZL/

提交回复
热议问题