Last active
June 27, 2025 19:42
-
-
Save maepon/6434811 to your computer and use it in GitHub Desktop.
Trust Formでフォームが長くなった時にフィールドの追加がめんどくさくなるのでフィールドのボックスが追従するようにしたJavaScript。検証は適当。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // admin/make-form.phpの最後にscriptタグで追加 | |
| (function($){ | |
| var $box = $('#standard-form'), | |
| boxBaseOffsetY = $box.offset().top; | |
| $box.css({ | |
| position: 'absolute', | |
| left:0, | |
| top:0, | |
| width: '100%' | |
| }).parent().css({ | |
| position: 'relative' | |
| }); | |
| function moveBox(){ | |
| var $t = $(this) | |
| toY = $t.scrollTop() - boxBaseOffsetY; | |
| if (toY < 0){ | |
| $box.css({top: 0}); | |
| }else{ | |
| $box.css({top: toY + 'px'}); | |
| } | |
| } | |
| $(window).scroll(moveBox); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment