简体   繁体   中英

Stop scrolling on Anchor click

<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<link href="font-awesome.css" rel="stylesheet">

</head>
<body leftmargin="0px" topmargin="0px" >
<div class="header">
    <div class="head"><div class="logo"><img src="logo.png"></div>
       <div class="menu"><a href="#main" >menu</a></div>
</div>
   <div id="main">
    <section id="nav">
        <ul><li><a href="#">Home</a></li>
        <li><a href="#new">Events</a></li>
        <li><a href="#tech">Technical</a></li>
        <li><a href="#">Schedule</a></li>
        <li><a href="#">Contact</a></li>
        </ul>
    </section>
    <div id="new"><h1 align="center">Content changed</h1></div>
    <div id="tech"><h1 align="center">Technical event</h1></div>
</div><br>
</body>
</html>

I want to stop jump to the id="main" when click on and want to stop for all anchor #new link to stop scroll and jump page should be stay as it is

I'm guessing you are attaching event listeners to the links. Here's an example I came up with using your code: http://jsfiddle.net/Rdsxk/

$(selector).on('click', function(){
 //add code you want to execute here
 return false 
});

Selector would be the class of the links you don't want to scroll.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM