如何使用jquery设置顶部位置 [英] How to set top position using jquery

查看:81
本文介绍了如何使用jquery设置顶部位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建自定义 div 滚动条并希望设置内容 div 的顶部位置.我的 jquery 代码如下:

containerOuterHeight=$("#messagePopUpContainer").outerHeight();contentOuterHeight=$("#content").outerHeight();contentTopPosition=$("#content").offset().top;警报(contentTopPosition"+contentTopPosition);警报(contentTopPosition-(containerOuterHeight/20));$("#content").offset().top=contentTopPosition-(containerOuterHeight/20);//$("#content").css("top",( contentTopPosition-(containerOuterHeight/20) ) + "px");alert("contentTopPosition"+$("#content").offset().top);//alert("Fontsize"+$('#content').css('font-size'));

和 html 是:

<a href='javascript:void(0);'id='popupanchor' onkeydown='PopupKeyHandler("' + elmId + '");'></a>

'+ methods.settings[elmId].text + '</div ><div id='popupReturn'>返回</div></div></div>'

解决方案

你可以使用 CSS 来解决这个问题:

$("#yourElement").css({ top: '100px' });

I am creating custom div scroller and want to set top position of content div. My jquery code is as below:

containerOuterHeight=$("#messagePopUpContainer").outerHeight();
            contentOuterHeight=$("#content").outerHeight();
            contentTopPosition=$("#content").offset().top;
            alert("contentTopPosition"+contentTopPosition);
            alert(contentTopPosition-(containerOuterHeight/20));
            $("#content").offset().top=contentTopPosition-(containerOuterHeight/20);
            //$("#content").css("top",( contentTopPosition-(containerOuterHeight/20) ) + "px");
            alert("contentTopPosition"+$("#content").offset().top);
            //alert("Fontsize"+$('#content').css('font-size') );

and html is:

<div id='messagePopUpContainer' style='background-color:#ffffff; overflow: hidden;'>
<a href='javascript:void(0);' id='popupanchor' onkeydown='PopupKeyHandler("' + elmId + '");'></a>

<div id='content' style='width:350px'>' + methods.settings[elmId].text + '</div >
<div id='popupReturn'>Return</div></div></div>'

解决方案

You can use CSS to do the trick:

$("#yourElement").css({ top: '100px' });

这篇关于如何使用jquery设置顶部位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆