简体   繁体   English

在ajax表单发送后刷新/重置jquery变量

[英]refresh / reset jquery variable after ajax form send

I am having trouble figuring this one out, can anyone help please? 我无法弄清楚这一点,有人可以帮忙吗?

I'm not sure if it's even possible, I need to refresh/reset the variable as I need to keep it's scope for other functions, so it can be used globally. 我不确定是否有可能,我需要刷新/重置变量,因为我需要保持其在其他函数中的作用范围,因此可以在全局范围内使用它。

I have this variable near the top of my jquery goodness... 我在我的jQuery天赋的顶部附近有这个变量...

var heightOne = $panelOne.height();

and I'm trying to refresh it when my ajax gravity form sends. 当我的ajax重力表单发送时,我正在尝试刷新它。

I have this binded function which will fire when the form has fulled reloaded, So I guess I can put my variable refresh/reset script inside here... 我有这个绑定的函数,当表单重新加载完成时会触发,所以我想我可以将变量刷新/重置脚本放在这里...

$(document).bind('gform_post_render', function(){

    // variable refresh code in here...     

    $slidePane.css({ 'height' : heightOne + 'px' }); // then this will follow and use new height taken from $panelOne updated variable  

});


But I'm struggling to find out where to start. 但是我在努力寻找起点。 Any help would be awesome thanks. 任何帮助将是非常感谢。



UPDATE 更新

This is my script in full, to show you what I'm trying achieve. 这是我的完整脚本,向您展示我正在尝试实现的目标。

$(window).load(function(){

    var $slidePane  = $("#sliding-pane"),

         $stageOne  = $("#nav-stage-1"),
         $stageTwo  = $("#nav-stage-2"),
         $stageThree = $("#nav-stage-3"),

         heightOne  = $("#panel-stage-1").height(),
         heightTwo  = $("#panel-stage-2").height(),
         heightThree = $("#panel-stage-3").height();

    $slidePane.css({ 'height' : heightOne + 'px' });

    $.fn.slideThree = function() {

        $slidePane.stop().animate({
                left : "0px",
                height : heightOne + 'px'
        }, 300);

        FB.Canvas.scrollTo(0, 510);

    };

    $.fn.slideThree = function() {

        $slidePane.stop().animate({
                left : "-680px",
                height : heightTwo + 'px'
        }, 300);

        FB.Canvas.scrollTo(0, 510);

    };

    $.fn.slideThree = function() {

        $slidePane.stop().animate({
                left : "-1360px",
                height : heightThree + 'px'
        }, 300);

        FB.Canvas.scrollTo(0, 510);

    };

    $stageOne.on('click', function () {

        $(this).slideOne();

    });

    $stageTwo.on('click', function () {

        $(this).slideTwo();

    });

    $stageThree.on('click', function () {

        $(this).slideThree();

    });

    $(document).bind('gform_post_render', function(){

        $slidePane.css({ 'height' : heightThree + 'px' });

    });

});  

I'd recommend you put overflow:hidden in the css of the slidePane; 我建议您将overflow:hidden在slidePane的css中; that way the dimensions will resize automatically. 这样,尺寸将自动调整大小。 You shouldn't need jquery for this. 您不需要为此的jQuery。

var $slidePane  = $("#sliding-pane"),
    /* ...other vars... */
    heightThree = $("#panel-stage-3").height();

    // Cache the height
    $('#panel-stage-3').data('origHeight', heightThree);


$(document).bind('gform_post_render', function(){
    $slidePane.css({ 'height' : $('#panel-stage-3').data('origHeight') + 'px' });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM