Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Scrolling Js that work for one element

Featured Replies

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  

 

  • 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

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.

  • 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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.