JavaScriptコードにconditionメソッドを渡したいと思います。このコードはInternet Explorer 10のバージョンでは機能しません。JavaScriptコードを使用したif条件で関数メソッドを使用するにはどうすればよいですか?
機能宣言をブロックに配置しないでください。関数式を使用するか、ステートメントを外部関数の先頭に移動します。
私はここでどのような機能を持つことができますか?
if(jQuery("header").attr("id") == "header-style-two")
{
function sticky_relocate() {
var window_top = jQuery(window).scrollTop();
var div_top = jQuery('#sticky-anchor').offset().top;
if (window_top > div_top) {
jQuery('.mainmenu-area').removeClass('light-menu');
//This is for when div in top
} else {
jQuery('.mainmenu-area').addClass('light-menu');
//This is for when div in not top
}
}
jQuery(function() {
jQuery(window).scroll(sticky_relocate);
sticky_relocate();
});
}
http://stackoverflow.com/questions/10069204/function-declarations-inside-if-else-statements – Mahi
おかげ@Mahi。これは私にとって非常に役に立ちます。ありがとうたくさん:)最初の場所で –