返回Javascript中的反向值
使用Ionic和Angular,我试图创建一个基于Ionic侧菜单的指令。现在它是基于他们的淡入淡出酒吧演示,看起来像这样返回Javascript中的反向值,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,使用Ionic和Angular,我试图创建一个基于Ionic侧菜单的指令。现在它是基于他们的淡入淡出酒吧演示,看起来像这样 .directive('fade', function ($timeout) { return { restrict: 'A', link: function ($scope, $element, $attr) { // Run in the next scope digest $tim
.directive('fade', function ($timeout) {
return {
restrict: 'A',
link: function ($scope, $element, $attr) {
// Run in the next scope digest
$timeout(function () {
// Watch for changes to the openRatio which is a value between 0 and 1 that says how "open" the side menu is
$scope.$watch('sideMenuController.getOpenRatio()', function (ratio) {
// Set the transparency of the fade bar
$element[0].style.opacity = Math.abs(ratio);
});
});
}
};
})
所以现在,.getOpenRatio
正在跟踪侧菜单的打开程度。现在我正在做的是,当比例变为1时,尝试淡出菜单内容。但我的问题是我不知道如何得到这个值的倒数。因此,内容的不透明度在关闭时设置为0,在打开时设置为1
我怎样才能“说”当开放比率为0时,我的内容不透明度为1,但当比率为1时,我的内容不透明度为0。我不知道这是否内置于JavaScript中,因此如果需要,我愿意将jQuery添加到项目中
感谢您的帮助。试试看
$element[0].style.opacity = 1 - Math.abs(ratio);
contentOpacity=1-比率
?哇,这么简单?我觉得自己像个白痴哈。谢谢你的快速回复。如果你想回答这个问题,我会给予奖励