【问题标题】:JQuery UI Slider resume after stopping on condition using return falseJQuery UI Slider在使用return false停止后恢复
【发布时间】:2017-07-02 07:14:51
【问题描述】:

这是带有调用的滑块元素。我试图在成功的情况下阻止它,但之后它就卡住了。我尝试添加else{ return true; },但正如预期的那样,它不会运行其余部分。如果我在代码运行的末尾移动 if else 块,则条件会触发,这不是我想要的。

$(".hdrHt").slider({
  orientation: "horizontal",
  range: "min",
  max: 22,
  min: 8,
  value: 15,
  create: function(){ $(this).find('.headHandle').text( $(this).slider("value")+'%'); },
  slide: function(e,ui){
        var hfs=currentVid.find('.ovlDivs').css('font-size').replace('px',''),hht=currentVid.find('.headerDiv').css('height').replace('px','');
        if((parseInt(hfs)+10)>parseInt(hht)){ return false; }
        currentVid.find('.middleDiv').css('height',(100-parseInt(currentVid.find('.ftrHt').slider("value"))-ui.value)+'%');
        currentVid.find('.headerDiv').css('height',ui.value+'%'); $(this).find('.headHandle').text(ui.value+'%');
      }
});

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-ui-slider


    【解决方案1】:

    好吧,我放弃得太快了,这很容易。但如果您有更清洁的解决方案,请继续。

    var stopPt=8;
    $(".hdrHt").slider({
      orientation: "horizontal",
      range: "min",
      max: 22,
      min: 8,
      value: 15,
      create: function(){ $(this).find('.headHandle').text( $(this).slider("value")+'%'); },
      slide: function(e,ui){
            if(ui.value>stopPt){
                currentVid.find('.middleDiv').css('height',(100-parseInt(currentVid.find('.ftrHt').slider("value"))-ui.value)+'%');
                currentVid.find('.headerDiv').css('height',ui.value+'%'); $(this).find('.headHandle').text(ui.value+'%');
            }
            var hfs=currentVid.find('.ovlDivs').css('font-size').replace('px',''),hht=currentVid.find('.headerDiv').css('height').replace('px','');
            if((parseInt(hfs)+15)>parseInt(hht)){ stopPt=ui.value; return false; }
          }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-11-20
      • 2013-06-09
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      相关资源
      最近更新 更多