简体   繁体   中英

using two different click animations in one nav bar

My website uses html with CSS file. My nav bar uses Jquery click animation. I want to add another level of animation to the nav functions, but can't figure out how to insert another click animation (slide/toggle) without disrupting the existing click animation (scrolling).

Here is how it is set up now

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jonah Rapino - Film Scoring</title>
<link rel="stylesheet" href="rapino.css" media="screen, projection"/>
<link href='http://fonts.googleapis.com/css?family=OFL+Sorts+Mill+Goudy+TT' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="" type="image/x-icon">
<style type="text/css">
</style>
</head>

<body>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
  $(function() {
$("#nav").click(function(e){
  e.preventDefault();
  var theClicked = $(e.target).attr("href"),
  targetImg = $(theClicked).offset().top;
  $("html,body").animate({
    scrollTop : targetImg -10,
  }, 1400);
//console.log(targetImg)
});
});
</script>
</body>

<div id="content"> 
<div id="nav"> 
<ul class="listless">
  <li><a href="#about">About</a></li>
  <li><a href="#current-work">Work</a></li>
  <li><a href="#feature-film-scores">Film</a></li>
  <li><a href="#silent-film-scores">Silent</a></li>
  <li><a href="#classical-music">Classical</a></li>
  <li><a href="#info">Info</a></li>
  <li><a href="#download">Download</a></li>
  <li><a href="#friends">Friends</a></li>
</ul>
</div>

What I want: I want to insert a toggle function to the Work link. When you click Work a pop down sub menu containing the links - Film, Silent, Classical appear and you can click on them and the page scrolls to the target indicated. Currently they are just static links.

I hope my language/layout isn't confusing or a waste of time here. Can anyone help?

Maybe something like

$('#nav a').click(function(e) {
   e.preventDefault();
   if($(this).attr('href') === '#current-work') {
      // do your animation for work
   }
   else {
      // do animation for all other items
      var targetImg = $($(this).attr('href')).offset().top;
      $("html,body").animate({
         scrollTop : targetImg -10,
      }, 1400);
   }
});

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