javascript - Apply Transition effect when adding and remove class -
trying add sliding transition effect when add , remove class. tried sticky nav js below:
lastscroll = 0; $(window).on('scroll',function() { var scroll = $(window).scrolltop(); if(scroll === 0){ $(".nav").removeclass("darkheader"); } else if(lastscroll - scroll > 0) { $(".nav").addclass("darkheader"); } else { $(".nav").removeclass("darkheader"); } lastscroll = scroll; });
my try:
lastscroll = 0; $(window).on('scroll',function() { var scroll = $(window).scrolltop(); if(scroll === 0){ $(".nav").removeclass("darkheader", 1000, "easeinoutquad"); } else if(lastscroll - scroll > 0) { $(".nav").addclass("darkheader", 1000, "easeinoutquad"); } else { $(".nav").removeclass("darkheader", 1000, "easeinoutquad"); } lastscroll = scroll; });
i'm trying adding 1000, "easeinoutquad"
, trying jquery without css3 (no css please).
problem fiddle >>
i'm trying implement slide effect this >>
try utilizing jquery ui
, .animate()
, .stop()
; adding .css("top", 0)
before adding .darkheader
class
, adding color: wheat
.darkheader
css
$(function() { lastscroll = 0; function _scroller() { var scroll = $(window).scrolltop(); if (scroll < 10) { $(".nav").stop() .animate({ backgroundcolor: "rgb(250, 227, 183)" }, { duration: 1000, easing: "easeinoutquad" }) .removeclass("darkheader"); } else if (lastscroll - scroll > 10) { if (!$(".nav").is(":animated")) { $(this).off("scroll"); $(".nav").stop() .css("top", -24) .animate({ top: 0, backgroundcolor: "rgb(0, 0, 0)" }, { duration: 1000, easing: "easeinoutquad", complete: function() { $(window).on("scroll.t", function() { if ($(window).scrolltop() < 1) { $(this).off("scroll.t") .on("scroll", _scroller).scroll() } }) } }) .addclass("darkheader"); } } else { $(".nav").stop() .animate({ backgroundcolor: "rgb(243, 221, 180)" }, { duration: 1000, easing: "easeinoutquad" }) .removeclass("darkheader"); } lastscroll = scroll; } $(window).on('scroll', _scroller) });
body { font-family: "rokkitt", helvetica, arial, sans-serif; font-size: 18px; line-height: 20px; background: #f8f8f0; margin: 0; } .darkheader { /*background-color: black !important; */ position: fixed; color: wheat; } .nav { width: 100%; background-color: wheat; padding: 10px; } .menu { float: right; cursor: pointer; margin-top: -8px; } #content { margin-top: 150px; padding-top: 20px; } .wrap { max-width: 800px; margin: 0 auto; padding: 0 40px; } #top span { white-space: nowrap; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> <div class="nav">sticky top navigation bar</div> <div class="wrap"> <h3>some filler text</h3> bacon ipsum dolor sit amet mollit ball tip occaecat brisket cupidatat meatball capicola. capicola rump turducken, elit shankle cupidatat pastrami duis fatback. sint occaecat kielbasa labore pastrami corned beef. sunt swine bacon, fugiat dolor aute anim jerky nostrud et venison shankle consectetur boudin landjaeger. pork chop sed turkey aute, duis corned beef pariatur short loin proident culpa. capicola filet mignon fugiat corned beef shank ea, commodo doner adipisicing eu salami. doner laboris pariatur beef ribs non id. andouille eu meatball consectetur ham hock. ea dolore cillum cow pork loin aliquip leberkas id est corned beef dolore t-bone. in salami jerky cupidatat et. ham hock irure reprehenderit chicken drumstick sausage ad, pig elit salami. tri-tip consectetur t-bone salami, sunt jerky exercitation ham ut tempor nostrud enim. beef ribs enim esse non sausage. chuck anim spare ribs ut ad deserunt, tri-tip chicken bacon tongue ball tip. est tongue doner eiusmod veniam sint tenderloin deserunt bresaola strip steak fugiat proident pastrami. <p>mollit turkey pork chop, drumstick tongue shank pastrami tempor. reprehenderit consequat excepteur, in eiusmod ut incididunt short loin adipisicing tenderloin capicola fugiat. ut non short ribs ball tip. elit beef non flank reprehenderit hamburger. fatback drumstick pancetta magna shankle corned beef pastrami spare ribs. quis dolore beef non, veniam aliqua sirloin consectetur laboris shoulder pork leberkas short loin. rump qui beef spare ribs drumstick andouille duis est esse irure strip steak labore. </p> <p>tongue filet mignon pancetta, elit pariatur nostrud deserunt excepteur tri-tip salami in nisi. ball tip beef fugiat, mollit officia jerky sirloin chuck dolore. sausage fugiat spare ribs, tongue pork belly ut in. t-bone fatback anim nisi minim culpa laboris andouille meatball ham ut.</p> <p>et turducken pork loin strip steak tempor enim nostrud magna minim qui adipisicing. pork nulla mollit dolore. nisi reprehenderit shank, hamburger jerky magna drumstick pancetta duis t-bone tempor cow proident ut. andouille sed beef ribs tail chuck deserunt mollit beef adipisicing ribeye landjaeger. shankle pig cillum aliquip, exercitation t-bone ground round prosciutto mollit chuck kevin brisket dolore ullamco. pork chop capicola culpa doner nostrud filet mignon pork loin voluptate qui ut in aliquip pork belly.</p> <p>deserunt pancetta pork loin cillum cupidatat laborum pork belly jerky short ribs prosciutto leberkas mollit non tail duis. laborum in pork chop, venison filet mignon voluptate tail reprehenderit pig shankle rump deserunt in cupidatat. landjaeger pork chop incididunt, irure occaecat mollit elit tenderloin excepteur anim kevin frankfurter tongue corned beef. id pork chop magna et non velit. boudin hamburger dolore eu ut culpa. in ut deserunt incididunt meatball ribeye, shoulder aute. cillum labore occaecat salami quis laborum. ex nulla pancetta ham hock tongue, andouille aute laborum velit strip steak beef ribs. id corned beef excepteur filet mignon drumstick est magna consequat veniam enim exercitation sunt venison strip steak biltong. cillum pancetta id quis biltong capicola corned beef. boudin tongue in pariatur proident ut pork belly magna nulla swine.</p> <p>ad aliquip officia, aute chuck qui veniam swine pancetta t-bone ribeye doner. culpa velit eiusmod, ball tip nisi consectetur nostrud et sausage bresaola eu dolore. turducken dolore irure commodo pork chop meatball duis short ribs, t-bone boudin bacon. aliquip ad tri-tip swine eiusmod. rump chicken kevin eu. voluptate biltong commodo, hamburger esse non tempor sausage cillum eiusmod ribeye sunt shankle. meatloaf short ribs voluptate brisket, pork belly bresaola ullamco chuck ball tip incididunt irure eu consequat hamburger leberkas. meatball occaecat filet mignon, jowl kielbasa exercitation reprehenderit bresaola venison. incididunt salami ham quis prosciutto pork loin cow irure labore venison sausage corned beef chicken. laboris jowl strip steak quis spare ribs. in hamburger et ea bresaola turkey.</p> <p>bacon ipsum dolor sit amet mollit ball tip occaecat brisket cupidatat meatball capicola. capicola rump turducken, elit shankle cupidatat pastrami duis fatback. sint occaecat kielbasa labore pastrami corned beef. sunt swine bacon, fugiat dolor aute anim jerky nostrud et venison shankle consectetur boudin landjaeger. pork chop sed turkey aute, duis corned beef pariatur short loin proident culpa. capicola filet mignon fugiat corned beef shank ea, commodo doner adipisicing eu salami. doner laboris pariatur beef ribs non id. andouille eu meatball consectetur ham hock. ea dolore cillum cow pork loin aliquip leberkas id est corned beef dolore t-bone. in salami jerky cupidatat et.</p>ham hock irure reprehenderit chicken drumstick sausage ad, pig elit salami. tri-tip consectetur t-bone salami, sunt jerky exercitation ham ut tempor nostrud enim. beef ribs enim esse non sausage. chuck anim spare ribs ut ad deserunt, tri-tip chicken bacon tongue ball tip. est tongue doner eiusmod veniam sint tenderloin deserunt bresaola strip steak fugiat proident pastrami. mollit turkey pork chop, drumstick tongue shank pastrami tempor. reprehenderit consequat excepteur, in eiusmod ut incididunt short loin adipisicing tenderloin capicola fugiat. ut non short ribs ball tip. elit beef non flank reprehenderit hamburger. fatback drumstick pancetta magna shankle corned beef pastrami spare ribs. quis dolore beef non, veniam aliqua sirloin consectetur laboris shoulder pork leberkas short loin. rump qui beef spare ribs drumstick andouille duis est esse irure strip steak labore. <p>tongue filet mignon pancetta, elit pariatur nostrud deserunt excepteur tri-tip salami in nisi. ball tip beef fugiat, mollit officia jerky sirloin chuck dolore. sausage fugiat spare ribs, tongue pork belly ut in. t-bone fatback anim nisi minim culpa laboris andouille meatball ham ut. et turducken pork loin strip steak tempor enim nostrud magna minim qui adipisicing. pork nulla mollit dolore. nisi reprehenderit shank, hamburger jerky magna drumstick pancetta duis t-bone tempor cow proident ut. andouille sed beef ribs tail chuck deserunt mollit beef adipisicing ribeye landjaeger. shankle pig cillum aliquip, exercitation t-bone ground round prosciutto mollit chuck kevin brisket dolore ullamco. pork chop capicola culpa doner nostrud filet mignon pork loin voluptate qui ut in aliquip pork belly.</p>deserunt pancetta pork loin cillum cupidatat laborum pork belly jerky short ribs prosciutto leberkas mollit non tail duis. laborum in pork chop, venison filet mignon voluptate tail reprehenderit pig shankle rump deserunt in cupidatat. landjaeger pork chop incididunt, irure occaecat mollit elit tenderloin excepteur anim kevin frankfurter tongue corned beef. id pork chop magna et non velit. boudin hamburger dolore eu ut culpa. in ut deserunt incididunt meatball ribeye, shoulder aute. cillum labore occaecat salami quis laborum. ex nulla pancetta ham hock tongue, andouille aute laborum velit strip steak beef ribs. id corned beef excepteur filet mignon drumstick est magna consequat veniam enim exercitation sunt venison strip steak biltong. cillum pancetta id quis biltong capicola corned beef. boudin tongue in pariatur proident ut pork belly magna nulla swine. ad aliquip officia, aute chuck qui veniam swine pancetta t-bone ribeye doner. culpa velit eiusmod, ball tip nisi consectetur nostrud et sausage bresaola eu dolore. turducken dolore irure commodo pork chop meatball duis short ribs, t-bone boudin bacon. aliquip ad tri-tip swine eiusmod. rump chicken kevin eu. voluptate biltong commodo, hamburger esse non tempor sausage cillum eiusmod ribeye sunt shankle. meatloaf short ribs voluptate brisket, pork belly bresaola ullamco chuck ball tip incididunt irure eu consequat hamburger leberkas. meatball occaecat filet mignon, jowl kielbasa exercitation reprehenderit bresaola venison. incididunt salami ham quis prosciutto pork loin cow irure labore venison sausage corned beef chicken. laboris jowl strip steak quis spare ribs. in hamburger et ea bresaola turkey. bacon ipsum dolor sit amet mollit ball tip occaecat brisket cupidatat meatball capicola. capicola rump turducken, elit shankle cupidatat pastrami duis fatback. sint occaecat kielbasa labore pastrami corned beef. sunt swine bacon, fugiat dolor aute anim jerky nostrud et venison shankle consectetur boudin landjaeger. pork chop sed turkey aute, duis corned beef pariatur short loin proident culpa. capicola filet mignon fugiat corned beef shank ea, commodo doner adipisicing eu salami. doner laboris pariatur beef ribs non id. andouille eu meatball consectetur ham hock. ea dolore cillum cow pork loin aliquip leberkas id est corned beef dolore t-bone. in salami jerky cupidatat et. ham hock irure reprehenderit chicken drumstick sausage ad, pig elit salami. tri-tip consectetur t-bone salami, sunt jerky exercitation ham ut tempor nostrud enim. beef ribs enim esse non sausage. chuck anim spare ribs ut ad deserunt, tri-tip chicken bacon tongue ball tip. est tongue doner eiusmod veniam sint tenderloin deserunt bresaola strip steak fugiat proident pastrami. <p>mollit turkey pork chop, drumstick tongue shank pastrami tempor. reprehenderit consequat excepteur, in eiusmod ut incididunt short loin adipisicing tenderloin capicola fugiat. ut non short ribs ball tip. elit beef non flank reprehenderit hamburger. fatback drumstick pancetta magna shankle corned beef pastrami spare ribs. quis dolore beef non, veniam aliqua sirloin consectetur laboris shoulder pork leberkas short loin. rump qui beef spare ribs drumstick andouille duis est esse irure strip steak labore. </p>tongue filet mignon pancetta, elit pariatur nostrud deserunt excepteur tri-tip salami in nisi. ball tip beef fugiat, mollit officia jerky sirloin chuck dolore. sausage fugiat spare ribs, tongue pork belly ut in. t-bone fatback anim nisi minim culpa laboris andouille meatball ham ut. <p>et turducken pork loin strip steak tempor enim nostrud magna minim qui adipisicing. pork nulla mollit dolore. nisi reprehenderit shank, hamburger jerky magna drumstick pancetta duis t-bone tempor cow proident ut. andouille sed beef ribs tail chuck deserunt mollit beef adipisicing ribeye landjaeger. shankle pig cillum aliquip, exercitation t-bone ground round prosciutto mollit chuck kevin brisket dolore ullamco. pork chop capicola culpa doner nostrud filet mignon pork loin voluptate qui ut in aliquip pork belly.</p> </div>
jsfiddle http://jsfiddle.net/9fbr320y/9/
Comments
Post a Comment