Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取jQuery中选择器后面的:的边距值_Jquery_Css - Fatal编程技术网

获取jQuery中选择器后面的:的边距值

获取jQuery中选择器后面的:的边距值,jquery,css,Jquery,Css,我正在使用一个自定义滑块,我有许多滑块指示器。两个指标之间应该有一条橙色的线,例如,如果我点击指标1,那么指标1和指标2之间就会有一条线,如果我点击指标2,那么指标2和指标3之间就会有一条线,依此类推。 对于这一行,我使用:after选择器。 CSS代码: .carousel-indicators li:after{ content: ""; width: 20px; height: 3px; background: orange; t

我正在使用一个自定义滑块,我有许多滑块指示器。两个指标之间应该有一条橙色的线,例如,如果我点击指标1,那么指标1和指标2之间就会有一条线,如果我点击指标2,那么指标2和指标3之间就会有一条线,依此类推。 对于这一行,我使用:after选择器。 CSS代码:

.carousel-indicators li:after{
    content: "";
    width: 20px;
    height: 3px;
    background: orange;
    top: 28%;
    left: 1%;
    position: absolute;
    display: inline-block;
}
HTML代码:-

 <!-- Carousel Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
<!-- Carousel Indicators End -->

Bot正在以未定义的形式提供输出。

请尝试此操作

$('.carousel-indicators li').click( function (){
        margLeft = $('.carousel-indicators li:after').css('margin-left');
        console.log(margLeft);
    });
使用
getPropertyValue()
getComputedStyle()
获取after元素的边距

关于
getComputedStyle()
方法在应用活动样式表并解析这些值可能包含的任何基本计算之后,返回一个包含元素的所有CSS属性值的对象。单个CSS属性值通过对象提供的API访问,或者通过CSS属性名称索引访问

关于
getPropertyValue()
方法接口返回包含指定CSS属性值的DOMString

您没有给
留下空白。转盘指示器li:after
所以它得到0px
$('.carousel indicators li')。单击(函数(){
var marginLeft=window.getComputedStyle(此“,:after”).getPropertyValue('margin-left');
console.log(marginLeft)
});
.carousel指示器li:之后{
内容:“;
宽度:20px;
高度:3倍;
背景:橙色;
最高:28%;
左:1%;
位置:绝对位置;
显示:内联块;
}


  • 你想要这样的东西吗@Ali Bhutta?如果有任何改变,我也很乐意改变答案。顺便说一句,谢谢:):D.谢谢你的努力,但它给了我0px作为输出:'(对你的努力投赞成票。希望这会鼓励你:)顺便说一句,谢谢:)@Ali Bhuttasame 2你,我在我的问题中还嵌入了HTML代码,希望你能告诉我为什么我仍然得到0px
    $('.carousel-indicators li').click( function (){
            margLeft = $('.carousel-indicators li:after').css('marginLeft');
            console.log(margLeft);
        });
    
    window.getComputedStyle(this, ':after').getPropertyValue('margin-left');