I'm working on a J3 site which I've had to use quite a bit of custom html/js code. I've reached a 'can't see the wood for the tree's moment'. Joomla and PHP I can do, jQuery - my old brain doesn't seem to understand.
I have a function which scrolls to a 'div'. The div moves position depending on screensize, on desktops/larger screens it is on the right hand side, smaller screens it moves below. When clicking on a link, it shows the related information in the div.
The code I have working just scrolls to the top of the 'div', perfect on mobiles but on desktops my client has asked for the scroll to be to the top of the page rather than the div.
The page can be viewed here
My jQuery is:
jQuery(document)
.on("click", ".timeline-pills .timeline-element", function(e) {
e.preventDefault();
const currentElement = $(this);
const dataTarget = currentElement.data("target");
const dataTargetElem = $("div.timeline-info#" + dataTarget);
$(".timeline-pills .timeline-element").removeClass("active");
currentElement.addClass("active");
$(".timeline-info").hide();
dataTargetElem.show();
});
// Scroll to section
jQuery(document).on('click', '.scrollTo', function(e) {
e.preventDefault();
// target element id
const id = $(this).attr('href');
// target element
const $id = $(id);
if ($id.length = 0) {
return;
}
// top position relative to the document
const pos = $id.offset().top;
// animated top scrolling
$('body, html').animate({
scrollTop: pos
});
});
The media query which switches the layout is:
@media only screen and (max-width: 768px) {
.home .hp-vt-image, .home.timeline-pills {
width:50%;
}
.home .service:not(:last-child):before {
left:74%;
padding:72px 0;
margin-top:-43px;
}
}
Any help is much appreciated.
Signing off as a very exhausted dev.
id="service-1" class="timeline-info"
hasmargin-top: 30px;
in css rules. You should just delete or comment out that rule as I see it. (I hope I did not misunderstand your issue...)