I created yii 1 application and used following script in order to navigate in view file:
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
But, when i created yii2 application and pasted this code, it did not work. Then, i created new menu_navigate.js js file and pasted code like
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
i registered this code in ThemeAsset using following code:
public $js = [
'Index/menu_navigate.js'
]
But, this code did not help me and it is not working. I could not manage to find any error.
In console screen it is showing following error messageGET http://all/themes/CompanyProfile/Index/menu_navigate.js
(Not found)