I'm in the process of creating a one-page website that includes standard sections like services, portfolio, contact, and blog. When users click on the navigation menu for 'services', 'portfolio', and 'contact', it smoothly scrolls to the desired section without any issues.
My unique idea is to implement a different scrolling effect when users navigate to the blog section - instead of the typical up and down scroll, I want it to scroll horizontally from right to left for an engaging user experience. Currently, this functionality is partially working but there's a small problem. When users are at the bottom of the page (e.g., the contact section) and try to navigate to the blog, it first scrolls to the top before moving horizontally to display the blog section.
To improve this, I aim to eliminate the unnecessary vertical scrolling to the top and just smoothly transition into the blog section with a horizontal scroll from the point where users are currently positioned.
Do you have any suggestions on how to achieve this seamless sideways scrolling effect? Or should I consider separating the blog section into its own independent HTML file?
Edit
Scrolling from the blog to any section or navigating between sections vertically:
$('html, body').animate({scrollLeft: -$(sectionName).offset().left}, "slow");
$('html, body').animate({scrollTop: $(sectionName).offset().top}, "slow");
Scrolling from any section to the blog:
$('html, body').animate({scrollTop: $(sectionName).offset().top}, "slow");};
$('html, body').animate({scrollLeft: $(sectionName).offset().left}, "slow");
I haven't included much code due to time constraints. Currently, my code functions in a way that if a user is on the contact section and clicks on the blog link, it scrolls to the top and then transitions horizontally to the blog as if it's a separate HTML page. My goal is to refine this behavior so that clicking on the blog from any section instantly shows the top of the blog without unnecessary vertical scrolling.