Về cơ bản, mặt trái của abs. Nếu tôi có: if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
slideNum = -slideNum
}
console.log(slideNum)
Không có vấn đề gì giao diện điều khiển luôn trả về một số dương. Làm cách nào để khắc phục điều này? Nếu tôi làm: if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
Nó hoạt động tho, nhưng nó không phải là "khô" và chỉ ngu ngốc khi có toàn bộ khối mã chỉ cho một if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
8.
Liam 26.3K27 Huy hiệu vàng116 Huy hiệu bạc183 Huy hiệu Đồng27 gold badges116 silver badges183 bronze badges Hỏi ngày 6 tháng 4 năm 2011 lúc 23:24Apr 6, 2011 at 23:24 Oscar Godsonoscar GodsonOscar Godson 30.8K40 Huy hiệu vàng114 Huy hiệu bạc199 Huy hiệu đồng40 gold badges114 silver badges199 bronze badges 0 Math.abs(num) => Always positive
-Math.abs(num) => Always negative
Tuy nhiên, bạn có nhận ra rằng đối với mã của bạn if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
If the index found is 3 and slideNum is 3, then 3 < 3-1 => false so slideNum remains positive?? Nó trông giống như một lỗi logic đối với tôi. Đã trả lời ngày 6 tháng 4 năm 2011 lúc 23:31Apr 6, 2011 at 23:31 RichardthekiwirichardthekiwiRichardTheKiwi 104K25 Huy hiệu vàng194 Huy hiệu bạc262 Huy hiệu Đồng25 gold badges194 silver
badges262 bronze badges Mặt trái của ABS là if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
9. Đã trả lời ngày 6 tháng 4 năm 2011 lúc 23:27Apr 6, 2011 at 23:27
JAKUB HAMPLJAKUB HAMPLJakub Hampl 39.2k10 Huy hiệu vàng75 Huy hiệu bạc106 Huy hiệu đồng10 gold
badges75 silver badges106 bronze badges 2 Công thức cơ bản để đảo ngược dương tính đến tiêu cực hoặc tiêu cực đến tích cực: i - (i * 2)
Giacomo1968 25.2k11 Huy hiệu vàng70 Huy hiệu bạc99 Huy hiệu đồng11 gold badges70 silver badges99 bronze badges
Đã trả lời ngày 14 tháng 8 năm 2012 lúc 21:57Aug 14, 2012 at 21:57 6 JavaScript có một toán tử chuyên dụng cho điều này: phủ định không. TL; DR: Đó là dấu hiệu trừ! Để phủ nhận một số, chỉ cần tiền tố nó với if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
8 theo cách có thể trực quan nhất. Không cần phải viết một hàm, sử dụng Math.abs(num) => Always positive
-Math.abs(num) => Always negative
1 nhân với Math.abs(num) => Always positive
-Math.abs(num) => Always negative
2 hoặc sử dụng toán tử bitwise.Không phủ định hoạt động trên các chữ số: let a = 10; // a is `10`
let b = -10; // b is `-10`
Nó cũng hoạt động với các biến: let x = 50;
x = -x; // x is now `-50`
let y = -6;
y = -y; // y is now `6`
Bạn thậm chí có thể sử dụng nó nhiều lần nếu bạn sử dụng toán tử nhóm (a.k.a. dấu ngoặc đơn: l = 10; // l is `10`
m = -10; // m is `-10`
n = -(10); // n is `-10`
o = -(-(10)); // o is `10`
p = -(-10); // p is `10` (double negative makes a positive)
Tất cả những điều trên cũng hoạt động với một biến là tốt. Đã trả lời ngày 13 tháng 6 năm 2020 lúc 2:35Jun 13, 2020 at 2:35
BrentonstrineBrentstrinebrentonstrine Huy hiệu vàng 20.6K2525 gold badges71 silver badges117 bronze badges Để có được phiên bản âm của một số trong JavaScript, bạn luôn có thể sử dụng toán tử bitwise Math.abs(num) => Always positive
-Math.abs(num) => Always negative
3.Ví dụ: nếu bạn có Math.abs(num) => Always positive
-Math.abs(num) => Always negative
4 và bạn cần chuyển đổi nó thành âm, bạn có thể làm như sau:a = ~a + 1;
Điều này sẽ dẫn đến Math.abs(num) => Always positive
-Math.abs(num) => Always negative
5 là Math.abs(num) => Always positive
-Math.abs(num) => Always negative
6. Penny Liu 13.3k5 Huy hiệu vàng71 Huy hiệu bạc89 Huy hiệu đồng5 gold badges71 silver badges89 bronze badges Đã trả lời ngày 1 tháng 1 năm 2015 lúc 7:34Jan 1, 2015 at 7:34 5 var x = 100;
var negX = ( -x ); // => -100
Đã trả lời ngày 16 tháng 3 năm 2018 lúc 12:25Mar 16, 2018 at 12:25 tpayne84tpayne84tpayne84 Phim huy hiệu bạc 18111 silver badge9 bronze badges 2
if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
0Điều này sẽ làm điều đó cho bạn. Đã trả lời ngày 29 tháng 5 năm 2019 lúc 7:43May 29, 2019 at 7:43
Vibhor Dubevibhor DubeVibhor Dube 3.2221 Huy hiệu vàng20 Huy hiệu bạc 30 Huy hiệu Đồng1 gold badge20 silver badges30 bronze badges
Bạn có chắc rằng sự kiểm soát đó sẽ đi vào cơ thể của Math.abs(num) => Always positive
-Math.abs(num) => Always negative
7? Như trong điều kiện trong Math.abs(num) => Always positive
-Math.abs(num) => Always negative
7 đã bao giờ giữ đúng? Bởi vì nếu không, cơ thể của Math.abs(num) => Always positive
-Math.abs(num) => Always negative
7 sẽ không bao giờ được thực thi và if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
0 sẽ vẫn tích cực. Tôi sẽ đoán rằng đây có lẽ là những gì bạn đang thấy.Nếu tôi thử những điều sau đây trong Firebug, nó dường như hoạt động: if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
1if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
1 cũng nên hoạt động. Như if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
2. Đã trả lời ngày 6 tháng 4 năm 2011 lúc 23:24Apr 6, 2011 at 23:24 Vivin Palithvivin paliathVivin Paliath 92.4K39 Huy hiệu vàng216 Huy hiệu bạc293 Huy hiệu Đồng39 gold badges216 silver
badges293 bronze badges 2 Nếu bạn không cảm thấy muốn sử dụng math.abs * -1, bạn có thể đơn giản nếu câu này: p if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
2Tất nhiên bạn có thể biến điều này thành một chức năng như thế này if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
3makenegative (-3) => -3 makenegative (5) => -5 Hi vọng điêu nay co ich! Math.abs có thể sẽ làm việc cho bạn nhưng nếu nó không phải là một chút Đã trả lời ngày 18 tháng 3 năm 2016 lúc 14:17Mar 18, 2016 at 14:17 Ash Pettitash PettitAsh Pettit Huy hiệu vàng 2151 Huy hiệu bạc9 Huy hiệu đồng1 gold badge3 silver badges9 bronze badges
3 if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
4Kết quả: if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
3if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
5Kết quả: if($this.find('.pdxslide-activeSlide').index() < slideNum-1){ slideNum = -slideNum }
console.log(slideNum)
4Nếu bạn chia cho âm 1, nó sẽ luôn luôn lật số của bạn.
Đã trả lời ngày 1 tháng 6 năm 2018 lúc 22:28Jun 1, 2018 at 22:28 Sử dụng 0 - x x là số bạn muốn đảo ngược Đã trả lời ngày 7 tháng 1 năm 2017 lúc 19:10Jan 7, 2017 at 19:10 2 Nó sẽ chuyển đổi mảng âm thành tích cực hoặc ngược lại if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
6 Đã trả lời ngày 25 tháng 1 năm 2020 lúc 7:33Jan 25, 2020 at 7:33
Flash Noobflash noobFlash Noob 2983 Huy hiệu bạc6 Huy hiệu Đồng3 silver badges6 bronze badges Trong vani JavaScript if ($this.find('.pdxslide-activeSlide').index() < slideNum - 1) {
_selector.animate({
left: (-slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
} else {
_selector.animate({
left: (slideNum * sizes.images.width) + 'px'
}, 750, 'InOutPDX')
}
7Trong đó số trên là số dương bạn định chuyển đổinumber above is the positive number you intend to convert Mã này sẽ chuyển đổi chỉ số dương sang các số âm đơn giản bằng cách nhân với -1 Đã trả lời ngày 12 tháng 3 năm 2019 lúc 20:42Mar 12, 2019 at 20:42 perfoperfoperfo
11 Huy hiệu bạc3 Huy hiệu đồng1 silver badge3 bronze badges |