February 13, 20206 yr I have an issue that my main navigation allows smooth scrolling but when i try and add the same function to the button links on the page it makes the nave highlight go off. I am really new to this and wonder if its as straight forward to add div tag elements to create the same effect. I have tried adding new js but it then makes the nav go weird as to where it lands on the page. HTML CODE <ul id="mainNav"> <a href="#home"> <img src="im/logo-top-right.png" alt="sub small logo"></a> <li class="active"><a href="#home">HOME</a></li> <li><a href="#about">ABOUT US</a></li> <li><a href="#list">EQUIPMENT LIST</a></li> <li><a href="#services">SERVICES</a></li> <li><a href="#contact">CONTACT</a></li> </ul> </nav> <section id="home"> <div class="video-container"> <video autoplay muted loop id="video"> <source src="im/1010001752-preview.mp4" type="video/webm"> <source src="im/1010001752-preview.mp4" type="video/mp4"> Your browser does not support HTML5 video. </video> <div class="text-box"> <img src="im/sub-main-logo.png" alt="sub small logo"> <h1>The specialist, market-leading brokerage service for quality second-hand ROV and underwater survey equipment.</h1> </div> <div class="downArrow bounce" id="testscrolllink"> <p><a href="#firstintro" > <img width="36" height="36" alt="the scrol down arrow" src="im/downarrow.png"/></a></p> </div> </div> </section> <div id="firstintro"> <div class="intro-text-outter"> <div class="intro-text"> <div class="item" data-aos="fade-right"> <h2>supporting the global subsea industry for over 20 years.</h2> </div> <p>Formerly known as MaRE Trans Ltd, we supply the largest listings for second-hand ROV and survey equipment with almost 2,000 items located worldwide, from Workclass ROVs and Tooling to CPTs and Side Scan Sonars.</p> <p>With over 1,500 subscribers, <strong>sub</strong> has a worldwide network of clients involved in ROV and survey projects, making us a trusted, knowledgeable and experienced underwater brokerage service in this sector.</p> </div> </div> </div> JS Code // Cache selectors var lastId, topMenu = $("#mainNav, .buttonscroll"), topMenuHeight = topMenu.outerHeight()+1, // All list items menuItems = topMenu.find("a"), // Anchors corresponding to menu items scrollItems = menuItems.map(function(){ var item = $($(this).attr("href")); if (item.length) { return item; } }); // Bind click handler to menu items // so we can get a fancy scroll animation menuItems.click(function(e){ var href = $(this).attr("href"), offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1; $('html, body').stop().animate({ scrollTop: offsetTop }, 1250); e.preventDefault(); }); // Bind to scroll $(window).scroll(function(){ // Get container scroll position var fromTop = $(this).scrollTop()+topMenuHeight; // Get id of current scroll item var cur = scrollItems.map(function(){ if ($(this).offset().top < fromTop) return this; }); // Get the id of the current element cur = cur[cur.length-1]; var id = cur && cur.length ? cur[0].id : ""; if (lastId !== id) { lastId = id; // Set/remove active class menuItems .parent().removeClass("active") .end().filter("[href=#"+id+"]").parent().addClass("active"); } }); I can add a link to the testing page if that is allowed. All i am looking for is the buttons to scroll without effecting the navigation. its the little bouncing bit at the bottom i want to smooth scroll http://thinkserver.co.uk/sub/ Any help greatly appreciated. thanks
February 13, 20206 yr Author a very rough and ready version of this if that helps. the the scroll down arrow element is what i want to scroll other than just jump to the tag. also if i change the other subscribe buttons to anything else the underline on the navigation will not register. hope this is all making sense. 😣 https://codepen.io/ian-caie/pen/vYOLNBR
February 13, 20206 yr Author 2 hours ago, Jack said: Could you create a working example on something like https://codepen.io? https://codepen.io/ian-caie/pen/vYOLNBR
February 13, 20206 yr The first one is because you're not targeting the down arrow the same way as the other links that have smooth scroll, you've missed off the 'buttonscroll' class basically. Can you give me an example of what you're trying to change the subscribe button to? It's probably another issue with selectors not working.
February 13, 20206 yr Author 17 minutes ago, Jack said: The first one is because you're not targeting the down arrow the same way as the other links that have smooth scroll, you've missed off the 'buttonscroll' class basically. Can you give me an example of what you're trying to change the subscribe button to? It's probably another issue with selectors not working. this issue i have is that when i add <div class="buttonscroll"> <div class="downArrow bounce"> <p><a href="#firstintro" > <img width="36" height="36" alt="the scrol down arrow" src="im/downarrow.png"/></a></p> </div> </div></div> the navigation underline no longer works. this is the same issue if i change the target for the first subscribe it also affects the navigation. its really odd thanks
February 14, 20206 yr Author 48 minutes ago, Jack said: Is this closer to fixing the issue https://codepen.io/jackpallot/pen/WNvryKa? not quite.. the navigation if you click on Equipment list and Services no long have the orange underline Ithink that is my main issue. thanks
Create an account or sign in to comment