javascript - Gradually apply styles ( transitions not seeming to work ) Possibly with js / jQuery? -
i'm trying gradually fade in scroll-bar. currently, how making scroll-bar appear adding class body changes overflow auto, looks jerky / abrupt.
here js code abruptly adds class shows scroll-bar:
var bodywidth = $('body').width(); var scrollwidth = 10; $('body').mousemove(function(e){ var x = e.pagex - this.offsetleft; if(x>bodywidth-scrollwidth) $('body').addclass("auto"); else $('body').removeclass("auto"); }); and here css corresponding clases:
body { margin:0; overflow:hidden; } .auto { overflow:auto; } how can make transition less abrupt? there better way adding class , removing class.
the scrollbars can customized via -webkit-scrollbar, can not animated (or @ least didn't succeded @ it), , support in other browser poor.
an alternative set div on scrollbar, make same color base div, , make gradually transparent show scrollbar
the html is:
<div class="container"> <div class="base"> <p>aaa aaaaa aaaaa aaaaaaaa aaaa aaa aaa aaaa bbbbbb bbbbbb cccc cccc cccc </p> </div> <div class="hide"> </div> </div> the css is:
.base { width: 100px; background-color: white; top: 0px; position: absolute; height: 130px; overflow: hidden; padding-right: 20px; } .base.clipped { overflow: auto; } .hide { position: absolute; width: 19px; height: 100%; right: 0px; background-color: white; top: 0px; -webkit-transition: 2s; z-index: 10; } .hide.clipped { background-color: transparent; } i keeping class of elements time, adding second class clipped both. set padding in element have scrollbars there space without rearranging layout. hide element can transitioned css, overflow not.
the javascript
$("*").click(function(){ var obj = $(".base"); var hid = $(".hide"); if (obj.hasclass("clipped")) { hid.removeclass("clipped"); settimeout(function() { obj.removeclass("clipped"); }, 2000); } else { hid.addclass("clipped"); obj.addclass('clipped'); } });
Comments
Post a Comment