问题
I am using nicescroll in my application. I have dedined like
$("#Total").niceScroll({
cursorwidth: '8px',
cursorborder: 'none',
cursorborderradius:'0px',
cursorcolor:"#39CCDB"
});
but I don't want to give the styles as above. I want to apply these using a class.For that I have implemented like
.scroll {
cursorwidth: '8px',
cursorborder: 'none',
cursorborderradius:'0px',
cursorcolor:"#39CCDB"
}
and
var scrollbar = $("#Total").niceScroll({});
scrollbar.addClass("scroll");
but is not working,tell me how to apply stylings with a class for nicescroll.
回答1:
When facing problems of the kind you can print the whole object in inspector and see what you can use (using console.log(nice)
). So here is my solution
var div = niceScroll({ ... });
var nice = div.getNiceScroll();
$(nice)[0].rail.addClass('class-for-vertical');
$(nice)[0].rail.addClass('class-for-horizontal');
回答2:
you can't do that but you may try
var options = {
cursorwidth: '8px',
cursorborder: 'none',
cursorborderradius:'0px',
cursorcolor:"#39CCDB"
};
$("#Total").niceScroll(options);
回答3:
You can use:
$("#Total").niceScroll({cursorcolor:"#39CCDB",cursorwidth:"8px",cursorborderradius:"0px",cursorborder: "none"});
See Docs
回答4:
JS:
$('.custom_scrollbar').each(function(i){
// ...
$(this).niceScroll({ ... });
// ...
$('.nicescroll-rails').eq(i).addClass('your_class_name');
// ...
});
CSS:
.nicescroll-rails.your_class_name div{
background-color:red !important; /* for cursorcolor:"red" */
}
回答5:
You can add class with jquery:
var $scrollbar = $(selector).niceScroll({});
$scrollbar.cursor.parent().addClass('nicescroll-cursor-parent');
回答6:
try below code will work for
var scrollbar = $("#Total").niceScroll({});
$("#Total").addClass("scroll");
.scroll {
cursorwidth: '8px',
cursorborder: 'none',
cursorborderradius:'0px',
cursorcolor:"#39CCDB"
}
来源:https://stackoverflow.com/questions/21903718/how-to-append-class-for-nicescroll