[英].css() not setting width value
我希望在應用程序中加載某些圖片時簡單地移動divs寬度。 因此,出於某種原因,我讀取了Div的寬度,然后添加128,然后使用.css()更改divs的新寬度。 由於某些原因,.css()函數不會隨着寬度的變化而更新。 它僅在加載的最后一張圖片上更新。 我真的不確定為什么會這樣。 這是一些代碼:
document.getElementById('back').onload = function(){
var width = $("#LoadingBar").css("width").replace(/[^-\d\.]/g, '');
width = parseInt(width);
var newwidth = width + increment;
newwidth = newwidth +"px";
$('#LoadingBar').animate({width:newwidth},"fast");
if(width == 1280) {
//This is another div that I show once all the pictures load
$("#everything").show();
}
}
關於我要打破的任何想法嗎?
使用jquery width屬性更新元素寬度。
css用於HTML元素的更深奧的屬性。
$("#LoadingBar").css("width")
成為:
$("#LoadingBar").width()
您也可以設置寬度
$("#LoadingBar").width(MyWidthValue);
只需執行此操作即可更改寬度
$(<your element>).width(function (a, w) {return w+=128});
如果您需要設置動畫
$(<your element>).animate({width:"+=128"},'fast');
而不是使用css width
使用: var width = $("#LoadingBar").width()
以獲取數字值。 然后增加它並追加單位
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.