Asking for help in working with anchors?

Hello!


I'm developing a site and in the menu of this website use anchor, since most of the content is on the main page, just in different places.


Reproduce the problem:

1) Go to the demo vamsms.ru (don't worry about texting there's nothing there, just had a free address to test)

2) Click on articles in menu. The address will be of the form mysite.ru/stati.php

3) Now click On the center. Since this info on the main page, it will throw us back to the anchor #about. The address will be of the form mysite.ru/index.html#about

So far so good


4) Now error! If you click on the Contacts section (also located on the main, tied to the anchor #contacts), then we will move to contacts, but the address would be mysite.ru/index.html#about, although it should mysite.ru/index.html#contacts


That is the kind of problem that haunts me. Are there any thoughts on how to solve it?
October 3rd 19 at 04:10
2 answers
October 3rd 19 at 04:12
Solution
The fact that you have there is a smooth scrolling script to the desired anchor, and most likely in function returns return false, which prevents the link to set a new address.
Yes, here is the text of this js:

anchorScroller function(el, duration) {
if (this.criticalSection) {
return false;
}
if ((typeof el != 'object') || (typeof el.href != 'string'))
return true;
var address = el.href.split('#');
if (address.length < 2)
return true;
address = address[address.length-1];
el = 0;
for (var i=0; i<document.anchors.length; i++) { if (document.anchors[i].name="=" address) el="document.anchors[i];" break; } (el="==" 0) return true; this.stopx="0;" this.stopy="0;" do +="el.offsetLeft;" while this.startx="document.documentElement.scrollLeft" || window.pagexoffset document.body.scrollleft; this.starty="document.documentElement.scrollTop" window.pageyoffset document.body.scrolltop; this. stopx="this.stopX" - this.startx; this.starty; ( (this.stopx="=" && (this.stopy="=" ) false; the this.criticalsection="true;" (typeof duration="=" 'undefined') this.duration="500;" else var date=new date(); this.start="date.getTime();" this.timer="setInterval(function" () x="(date.getTime()" this.start) this.duration; (x> 1)
X = 1;
var Y = ((-Math.cos(X*Math.PI)/2) + 0.5);
cX = Math.round(this.startX + this.stopX*Y);
cY = Math.round(this.startY + this.stopY*Y);
document.documentElement.scrollLeft = cX;
document.documentElement.scrollTop = cY;
document.body.scrollLeft = cX;
document.body.scrollTop = cY;
if (X == 1) {
clearInterval( this.timer);
this.criticalSection = false;
}
}, 10);
return false;
}

</document.anchors.length;>
- Donny_Gerlach commented on October 3rd 19 at 04:15
Well, at the end of the see — return false. If fast then remove from the link "Contacts" on the onclick handler, if you want to leave the animation you will need the script slightly finished. - arthur.Armstron commented on October 3rd 19 at 04:18
Thank you very much) - Donny_Gerlach commented on October 3rd 19 at 04:21
October 3rd 19 at 04:14
After the line
clearInterval( this.timer);

insert this line:
location.hash: = address;
Everything works. - Donny_Gerlach commented on October 3rd 19 at 04:17

Find more questions by tags HTML