【问题标题】:tether element position incorrect until viewport change在视口更改之前,系绳元素位置不正确
【发布时间】:2017-03-22 01:35:57
【问题描述】:

我一直在玩很棒的插件:tether

我在手动加载引导程序 (v3) 弹出框时遇到问题,视口外的弹出框会显示在视口底部的错误位置。所以我决定尝试使用这个插件作为替代方案。

我一直在尝试使用基本的系绳选项来验证我的表单中的一个输入,该表单是使用 laravel 表单生成器制作的。 (form-group 的输入是目标元素)。

问题:

但由于某种原因,它似乎加载到目标元素的左侧(位置不正确)。当视口发生变化(页面调整大小或滚动等)时,它会更新到目标元素的右侧(在正确的位置)。

我不知道为什么会这样,有什么想法可以让我把它加载到正确的位置吗?

示例:

页面加载(位置不正确):

视口变化(正确位置):

HTML:

{!! Form::model( $article = new \App\Article, ['id' => 'form-article', 'route' =>'articles.store', 'class' => 'row']) !!}

<div class="row">
    <div class="form-group col-lg-12 title">
    {!! Form::text('title', null, ['id' => 'title', 'class' => 'form-control', 'placeholder' => 'Title']) !!}
    </div>
</div>
<div class="row">
    <div class="form-group col-lg-12 body">
        {!! Form::textarea('body', null, ['id' => 'body', 'class' => 'form-control', 'placeholder' => 'Body']) !!}
    </div>
</div>

{!! Form::close() !!}

<script type="text/javascript">
    $( document ).ready(function()
    {
        var errors = ({!! json_encode($errors->toArray()) !!});
        var form = ({!! json_encode($form) !!});
        console.log(errors);
        outputValidationPopovers(form, errors);
    });
</script>

JAVASCRIPT:

function outputValidationPopovers(formId, errors)
{
    $.each(errors, function (eKey, messages)
    {
        var $newPopover =  $('<div class="tether-'+eKey+'">stuff</div>');
        $newPopover.css('z-index', '1030').css('background-color', 'red');
        $(formId).append($newPopover);

        new Tether(
            {
                element: '.tether-'+ eKey,
                target: '.'+eKey,
                attachment: 'middle right',
                targetAttachment: 'middle right',
            });
   });
}

【问题讨论】:

    标签: javascript twitter-bootstrap laravel-5 tether


    【解决方案1】:

    没有关于如何解决这个问题的建议......所以我最终通过使用另一个使用 tether 作为依赖的插件来解决这个问题。这个插件被称为drop.js,非常适合所需的要求。我更改了函数以包含它而不是系绳初始化。

            var drop = new Drop({
    
                target: $input.closest('.form-group')[0],
                content: messages[0],
                classes: 'drop-theme-arrows-bounce drop-danger drop-form-'+formId+' target-' + eKey + ' ' + popoverClass,
                position: 'right middle',
                openOn: 'always'
            });    
    

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 2021-03-30
      • 2018-06-21
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多