使用JavaScript查找CSS浮动
我不熟悉使用JavaScript。如何确定图像的浮动属性(左/右)?我想应该是这样的-使用JavaScript查找CSS浮动,javascript,jquery,css,Javascript,Jquery,Css,我不熟悉使用JavaScript。如何确定图像的浮动属性(左/右)?我想应该是这样的- var positionFloat = $(this).position(); 我正在使用来自的以下标题覆盖代码。很好的覆盖,我只需要能够浮动标题跨度与图像-左或右 谢谢 // display image caption on top of image $("#content img").each(function() { var imageCaption = $(this).attr("alt"); i
var positionFloat = $(this).position();
我正在使用来自的以下标题覆盖代码。很好的覆盖,我只需要能够浮动标题跨度与图像-左或右
谢谢
// display image caption on top of image
$("#content img").each(function() {
var imageCaption = $(this).attr("alt");
if (imageCaption != '') {
var imgWidth = $(this).width();
var imgHeight = $(this).height();
var position = $(this).position();
var positionTop = (position.top + imgHeight - 26)
$("<span class='img-caption'><em>"+imageCaption+"</em></span>")
.css({"position":"absolute", "top":positionTop+"px", "left":"0", "width":imgWidth +"px"})
.insertAfter(this);
}
});
//在图像顶部显示图像标题
$(“#内容img”)。每个(函数(){
var imageCaption=$(this.attr(“alt”);
如果(图像标题!=''){
var imgWidth=$(this).width();
var imgHeight=$(this).height();
var position=$(this.position();
变量positionTop=(position.top+imgHeight-26)
$(“”+imageCaption+“”)
.css({“位置”:“绝对”,“顶部”:位置顶部+“px”,“左侧”:“0”,“宽度”:imgWidth+“px”})
.在(本)之后插入;
}
});
将标题放置在图像顶部的最简单方法是将图像和标题放在同一个包含div中,将容器声明为位置:相对,然后在文本上使用绝对定位将其相对于图像顶部的容器进行定位
下面是一个例子:
约翰·缪尔小道上的雷湖
.集装箱{
位置:相对位置;
}
.标题{
位置:绝对位置;
顶部:10px;
左:140像素;
颜色:黑色;
字号:28px;
}
您可以使用css属性获取float的值。像这样
var sideFloat = $(this).css('float');
您的问题与CSSfloat
属性无关,是吗?看起来你只是在问你如何找到一个物体的绝对位置,这样你就可以手动定位它旁边的物体。如果是这样的话,请从标题和问题中删除float
这个词,这只会让人们对你的问题感到困惑。
var sideFloat = $(this).css('float');