I am looking for combine these codes below
document.getElementsByTagName("a").addEventListener("click", myFunction);
function myFunction(item) {
window.location = (""+window.location).replace(/#[A-Za-z0-9_]*$/,'')+"#"+item;
}
Combine with this
var duration = 10;
var Ypos = 400;
var timerID = setInterval(function() {
window.scrollBy(0, duration);
if( window.pageYOffset >= Ypos )
clearInterval(timerID);
}, 13);
What I want is the window location as var Ypos, is this possible?
HTML
<div class="menu">
<a href="#item_one">Item 1</a>
<a href="#item_two">Item 2</a>
<a href="#item_three">Item 3</a>
<a href="#item_four">Item 4</a>
</div>
<div id="item_one">item_one and more text</div>
<div id="item_two">item_two and more text</div>
<div id="item_three">item_three and more text</div>
<div id="item_four">item_four and more text</div>