我尝试使用 jQuery 来检测 div (.field_slide-produit) 的位置,因此我可以使用该位置将另一个 div (.slider-content) 恰好放在左下角的下方,我需要替换此 div 在窗口调整大小时动态显示。
我已经使用了这段代码,但它不起作用,知道为什么吗?
var offset = $('.field_slide-produit').offset();
var height = $('.field_slide-produit').height();
var width = $('.field_slide-produit').width();
var top = offset.top + height + "px";
var right = offset.left + width + "px";
$('.slider-content').css( {
'position': 'absolute',
'right': right,
'top': top
});
// listen the window changes and correct the newdiv position
$(window).resize(function(){ slider-content(); });
此代码位于代码笔中:http://codepen.io/Laurentfrom47/pen/wJEKVb
谢谢
最佳答案
你在那里包含了 jquery 文件吗?
同样在调整窗口大小时,slider-content() 函数正在调用但未定义
function slider-content(){
$('.slider-content').css( {
'position': 'absolute',
'right': right,
'top': top
});
}
检查这几点,你会得到你想要的结果
关于javascript - 将一个 div 动态定位在另一个下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042912/