【问题标题】:Modify the width of :after pseudo CSS element from JQuery [duplicate]修改 :after 来自 JQuery 的伪 CSS 元素的宽度 [重复]
【发布时间】:2017-10-31 05:08:10
【问题描述】:

我正在尝试动态更改 :after 中元素的宽度。但它没有反映。有人可以帮忙吗!

$(function(){
var a=20;
$(".progress:after").width(a+"%"); 
// This is not showing 20%. Still shows 50% which was coded in CSS
});
.progress {
    width:200px;
    height:50px;
    border:1px solid black;
    position:relative;
}
.progress:after {
    content:'\A';
    position:absolute;
    background:black;
    top:0; bottom:0;
    left:0; 
    width:50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="progress"></div>

这是 JSFidle 的 Link

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

您应该使用现在可用的,html5 progress element

$(function() {
  var a = 20;
  $("progress").prop('value', a);
});
progress {
    width:200px;
    height:50px;
    border:1px solid black;
    position:relative;
    background:transparent;
}
::-webkit-progress-bar{background:transparent;}

::-moz-progress-bar{background-color:black;}
::-ms-fill{background-color:black;}
::-webkit-progress-value{background-color:black;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<progress value="50" max="100"></progress>

【讨论】:

    猜你喜欢
    • 2015-05-06
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2011-08-14
    • 2018-01-21
    相关资源
    最近更新 更多