我想写一个condicional语句,检测div是否少于“transform”:“translate3d(-650px,0,0)”。 div是这样的:
<div class="owl-stage" style="transform: translate3d(0px, 0px, 0px); transition: 0.25s; width: 1055px; padding-left: 40px; padding-right: 40px;"></div>
我找不到正确的写作方式。这不起作用:
if ($(".owl-stage").css("transform") <= "translate3d(-650px, 0px, 0px)"){
console.log("hello");
}
答案 0 :(得分:2)
如果你想检查两个值的abscissa是否小于,请尝试
function getAbcissa(translate3dValue) {
var value = translate3dValue.indexOf("matrix") != -1 ? parseInt(translate3dValue.split(",")[4]) : Number(translate3dValue.match(/((-?)\d+(?=px))/g)[0]);
return value;
}
if ( getAbcissa($(".owl-stage").css("transform")) <= getAbcissa("translate3d(-650px, 0px, 0px)")){
console.log("hello");
}
tx
是表示翻译向量的横坐标。
<强>演示强>
function getAbcissa(translate3dValue) {
var value = translate3dValue.indexOf("matrix") != -1 ? parseInt(translate3dValue.split(",")[4]) : Number(translate3dValue.match(/((-?)\d+(?=px))/g)[0]);
return value;
}
if (getAbcissa($(".owl-stage").css("transform")) <= getAbcissa("translate3d(-650px, 0px, 0px)")) {
console.log("hello");
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="owl-stage" style="transform: translate3d(-800px, 0px, 0px); transition: 0.25s; width: 1055px; padding-left: 40px; padding-right: 40px;"></div>
&#13;