- jQuery's css方法中的运算符在IE8中不工作
-= operator in jQuery's css method not working in IE8
由于某种原因,看起来jQuery在css()
中对-=
的处理在IE8中不起作用。下面的代码没有出现任何错误,但也不能正常工作。我已经把范围缩小到上面提到的那个操作符了。
var postCount = $(".postsWrapper .window .posts article").length;
var numberOfPages = Math.ceil(postCount / 3);
var currentPage = 1;
var transitioning = false;
$(".postsWrapper button").click(function() {
var direction = $(this).attr("data-direction");
var postWindowWidth = $(".postsWrapper .window").width();
if (direction == "next" && currentPage < numberOfPages && transitioning == false) {
transitioning = true;
// the below line does nothing in IE8
$(".postsWrapper .window .posts").css("marginLeft", "-=" + postWindowWidth);
setTimeout(function() {
transitioning = false;
}, 1000);
currentPage++;
} else if (direction == "previous" && currentPage > 1 && transitioning == false) {
transitioning = true;
// the below line does nothing in IE8
$(".postsWrapper .window .posts").css("marginLeft", "+=" + postWindowWidth);
setTimeout(function() {
transitioning = false;
}, 1000);
currentPage--;
}
});
见http://www.weblinxinc.com/beta/candy-controls/demo/site/index.htm
问题是,你的margin-left
属性是开始与值auto
,所以jQuery不能增加/减少它。实例(来源如下)
如果你最初将它设置为一个数值,它将开始工作。生活例子
这可能是一个jQuery bug,你可以检查他们的列表,看看它是否存在。
下面是实际示例的源代码:
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>
<div id="test">I'm the test div</div>
<script>
(function() {
"use strict";
// The following line is only in the second example, the one that works;
// without it, it doesn't work (in IE8) even though it does in Chrome
$("#test").css("marginLeft", 0);
var counter = 0;
var up = true;
display("Initial marginLeft: " + $("#test").css("marginLeft"));
setInterval(function() {
if (up) {
$("#test").css("marginLeft", "+=5");
} else {
$("#test").css("marginLeft", "-=5");
}
++counter;
if (counter > 10) {
counter =0;
up = !up;
}
}, 200);
function display(msg) {
$("<p>").html(String(msg)).appendTo(document.body);
}
})();
</script>
</body>
</html>
相关文章:
- 这是什么 ==- javascript 运算符
- Recaptcha在IE7和IE8中不起作用
- jQuery/JS包含运算符或类似运算符
- Javascript逻辑运算符和字符串/数字
- 模运算符前的双水平线
- Joomla Gantry Framework ie8 LESS/CSS
- 为什么jQuery 1.8不能在IE8和InternetExplorer9中使用?(截至2012年9月的IE9最新版本)
- 在IE8中不起作用的元素上触发单击事件
- jQuery's trim()的前缀为not运算符
- Javascript,如果条件在没有&&逻辑运算符当&&它不起作用
- 谷歌地图v3标记没有显示ie8和9
- 如果在构造函数中有“返回”,则在 JavaScript 中的新运算符中做了什么
- 数据-在IE8中不起作用
- 如何使用排列运算符来获取具有命名参数的函数的所有参数
- JavaScript 中三元条件和逻辑和运算符的运算符优先级
- 用于验证JS中逻辑运算符表达式的正则表达式
- 什么's是相当于LINQ's SelectMany运算符
- JavaScript-===vs===运算符性能
- 无法在 IE 9 中传递此运算符的值,而它在 IE7 和 IE8 中工作正常
- - jQuery's css方法中的运算符在IE8中不工作