Looking for a solution to manage parallax on mobile devices in my HTML template:
<div width-watcher>
<div parallax-bg parallax-active="!(tablet || mobile)">
...
</div>
</div>
The width-watcher
includes boolean values for mobile, tablet, and screen. I need to evaluate the expression "!(tablet || mobile)"
to pass it to the parallax-bg
directive, disabling parallax on mobile devices.
I've attempted various methods in the parallax-bg
:
- Using
scope.$eval(attr.parallaxActive)
results in"undefined"
- Accessing scope.parallaxActive directly with:
"&"
yields a function that returns"undefined"
"="
also returns"undefined"
"@"
provides"!(tablet || mobile)"
After exhausting my options, I'm seeking additional solutions as English is not my first language, potentially missing some answers on Google.
Below is the code snippet for my background-parallax directive:
.directive('parallaxBackground', function($window) {
return {
transclude: true,
template: '<div ng-transclude></div>',
scope: {
parallaxRatio: '@',
parallaxOffset: '@',
},
link: function(scope, elem, attrs) {
var scopeActive = scope.$eval(attrs.parallaxActive);
var ...
if(scopeActive){
...
}
}
};