jquery Position() 失败
我有一个工具提示,正在通过 ajax 获取数据。我的问题是我想调整框的高度以适应数据(只是一些标记)。
该框是绝对定位的,我希望顶部定位根据框的大小进行更改,以便它的底部边框始终接触下面的元素位置。
在 Chrome 中,这工作正常。但在 FireFox 中,我似乎无法让它工作。我尝试通过调用 .position().top 以及检索 css 值 .css('top') 来获取初始顶部 css 值。在 FF 中都不起作用。我不知道该怎么办。
var popup=$('#saved_descr_wrap');
var cur_height=popup.height();
var cur_top=popup.css('top');
cur_top=parseInt(cur_top);
var entryHover = function(event){
var favorite_id=2;
popup.show();
// var fave_id=$(event.target).closest('tr').attr('data-postid');
$.get('{{Site}}/favorites/view/', {id:favorite_id}, function(data){
popup.find('img').hide();
$('#saved_note').text(data);
var new_height=popup.height();
var c=cur_top + cur_height - new_height;
popup.css('top', c);
});
};
var exitHover=function(event){
// popup.hide();
popup.css('top',cur_top);
$('#saved_note').text('');
popup.find('img').show();
};
$('tbody tr').hoverIntent({over:entryHover,out:exitHover});
这是我对 jQuery UI 的尝试(也是失败的):
var entryHover = function(event){
popup.position({my:"right bottom",at:"top right", of:"#main_box"});
popup.show();
var fave_id=$(event.target).closest('tr').attr('data-postid');
$.get('{{Site}}/favorites/view/', {id:fave_id}, function(data){
popup.find('img').hide();
$('#saved_note').text(data);
});
};
var exitHover=function(event){
popup.hide();
popup.position({my:"right bottom",at:"top right", of:"#main_box"});
$('#saved_note').text('');
popup.find('img').show();
};
$('tbody tr').hoverIntent({over:entryHover,out:exitHover});
I have a tool tip who's data is being fetched via ajax. My issue is that I want to adjust the height of the box to fit the data (just some markup).
The box is absolutely positioned and I want the top positioning to change based on the size of the box such that it's bottom border is always touching an element position below.
In chrome, this is working fine. But in FireFox, I can't seem to get it to work. I've tried to get the initial top css value by calling .position().top and also by retrieving the css value .css('top'). Neither works in FF. I'm not sure what to do.
var popup=$('#saved_descr_wrap');
var cur_height=popup.height();
var cur_top=popup.css('top');
cur_top=parseInt(cur_top);
var entryHover = function(event){
var favorite_id=2;
popup.show();
// var fave_id=$(event.target).closest('tr').attr('data-postid');
$.get('{{Site}}/favorites/view/', {id:favorite_id}, function(data){
popup.find('img').hide();
$('#saved_note').text(data);
var new_height=popup.height();
var c=cur_top + cur_height - new_height;
popup.css('top', c);
});
};
var exitHover=function(event){
// popup.hide();
popup.css('top',cur_top);
$('#saved_note').text('');
popup.find('img').show();
};
$('tbody tr').hoverIntent({over:entryHover,out:exitHover});
Here's my shot at jQuery UI (also a fail):
var entryHover = function(event){
popup.position({my:"right bottom",at:"top right", of:"#main_box"});
popup.show();
var fave_id=$(event.target).closest('tr').attr('data-postid');
$.get('{{Site}}/favorites/view/', {id:fave_id}, function(data){
popup.find('img').hide();
$('#saved_note').text(data);
});
};
var exitHover=function(event){
popup.hide();
popup.position({my:"right bottom",at:"top right", of:"#main_box"});
$('#saved_note').text('');
popup.find('img').show();
};
$('tbody tr').hoverIntent({over:entryHover,out:exitHover});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能够使用 jQuery UI 功能吗?如果可以的话,您是否研究过 位置函数?
示例
Are you able to use jQuery UI functionality? If you can, have you looked into the position function?
Example