Last active
December 22, 2015 06:59
-
-
Save maepon/6434811 to your computer and use it in GitHub Desktop.
Trust Formでフォームが長くなった時にフィールドの追加がめんどくさくなるのでフィールドのボックスが追従するようにしたJavaScript。検証は適当。
This file contains 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