jQuery在第一次打开页面时不起作用

拉玛·普里亚(Rama Priya)

通过使用jQuery,我将div垂直放置在窗口的中心位置。此脚本不支持$(document).ready(function(),但仅在调整窗口大小后才开始工作。

我需要的是工作,而加载页面,第一时间itself.Refer小提琴

HTML:

<div class="welcomer">
  <center>
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </center>
</div>

CSS:

body {
    background: #ccc;
    color:#000;
}
.welcomer {
    width: 100%;
    background: #fff;
}

jQuery的

$(document).ready(function(){

$(window).resize(function(){

    $('.welcomer').css({
        position:'absolute',
        "top": ((($(window).height() - $('.welcomer').outerHeight()) / 2) + $(window).scrollTop() + "px"),
        "left": ((($(window).width() - $('.welcomer').outerWidth()) / 2) + $(window).scrollLeft() + "px")
    });


// To initially run the function:
$(window).resize();

});
阿伦·P·约翰尼(Arun P Johny)

看起来像您$(window).resize()在调整大小处理程序中调用

$(document).ready(function () {
    $(window).resize(function () {
        $('.welcomer').css({
            position: 'absolute',
            "top": ((($(window).height() - $('.welcomer').outerHeight()) / 2) + $(window).scrollTop() + "px"),
            "left": ((($(window).width() - $('.welcomer').outerWidth()) / 2) + $(window).scrollLeft() + "px")
        });

    }).resize(); // To initially run the function:
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

jQuery事件第一次不起作用

jQuery脚本第一次不起作用

插值在第一次加载页面时不起作用

JQuery UI对话框按钮的启用和禁用在第一次打开时不起作用,但在以后的打开中却起作用

jQuery 在第一次点击时不起作用

Focusout 事件在输入事件 jQuery 中的第一次激活时不起作用

JQuery 在第一次点击时不起作用,但在它之后工作

我的jQuery代码在第一次点击时不起作用?

Ajax 在第一次提交时不起作用,页面刷新后只有结果才会刷新

MouseListener 第一次不起作用

输入.on('keydown')第一次不起作用

ExpandableListView setAlpha第一次不起作用

toggleClass()在第一次后不起作用

ajaxSubmit()OnProgress第一次不起作用

slideDown第一次不起作用

第一次解析 JSON 不起作用

搜索第一次点击不起作用

反应:动态位置在第一次渲染时不起作用

Viewflipper动画在第一次滑动时不起作用

“反应”单选按钮在第一次单击时不起作用

javascript切换在第一次按下时不起作用

html Javascript提交按钮在第一次单击时不起作用

onClick 事件在第一次点击时不起作用

第一次单击MaterialUI FormControl API TextField时onClick不起作用

react-simple-image-slider 在第一次渲染时不起作用

ReactJS - 模态在第一次点击时不起作用

CircularReveal动画在第一次尝试时不起作用

第一次单击时按钮不起作用

Tooltipster插件在第一次尝试时不起作用