![](/img/trans.png)
[英]custom sorting scientific notation using jQuery plugin dataTables
[英]Preventing jQuery from using Scientific Notation in $.Animate()?
如何防止jQuery使用科學記數法-jQuery.animate ()函數中的1.2e + 07而不是12,000,000 ?
使用: $('body').css({ backgroundPositionX: 12000000 + 'px' });
轉換為: background-position-x: 1.2e+07px;
預期結果: background-position-x: 12000000px;
一旦數字達到一百萬(1,000,000),就會開始發生這種情況:
反過來,這導致我的應用程序表現異常。 我想要純凈,簡單的整數-這些科學廢話都不是! 我環顧四周,但找不到與jQuery庫相關的任何內容。 僅純JS函數。
注意1:不僅是動畫,而且還有$ .css()。 我假設其他jQuery函數也相似。
注意2:我認為瀏覽器無法做到這一點,因為如果我手動輸入該值,那么在您達到通常的最大32位整數之前,它都可以正常工作
為什么這是個問題:
12000321轉換為: 1.20003e + 07
然后將1.20003e + 07轉換回整數時,我得到: 12000300
當您到達“科學計數法”時,步長為100s而不是1s,並且不夠具體。
謝謝你考慮我的問題
哇...花了我很長時間,但我終於設法找到一種方法。
經過大量測試,我注意到將直接字符串傳遞給$ .attr()並沒有將數字轉換為科學計數法。
我創建了一個自定義動畫,然后將style屬性手動設置為字符串。
似乎可以正常工作並以一位數而不是100s的速度增長!
$({
x: this.x,
y: this.y
}).animate({
x: x,
y: y
}, {
easing: this.motion_type,
duration: this.duration,
step: function(now, fx) {
var current_styles = $('.area').attr('style'),
current_styles = string = current_styles.split(" ");
var x = parseFloat(current_styles[1].replace('px', '').replace(';', ''));
var y = parseFloat(current_styles[2].replace('px', '').replace(';', ''));
if ('x' === fx.prop) {
x = now;
} else if ('y' === fx.prop) {
y = now;
}
$('.area').attr({ style: 'background-position: ' + x + 'px ' + y + 'px;' });
},
complete: function() {
t.stopNow();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.