How to sticky nicedit panel?

喜你入骨 提交于 2019-12-24 14:31:05

问题


I think you know it, you have a larger text and the panel is at the top of your edit area and if you will use the panel you must scroll. It would be nice, if the panel sticky at the top of the window, instead of going away.

Any idea, how to sticky the panel?


回答1:


Easier than I thought.

var sticky_panelContain_offset_top = $('div.nicEdit-panelContain').offset().top;
    var sticky_panelContainer = function(){
    var scroll_top = $(window).scrollTop();
    if (scroll_top > sticky_panelContain_offset_top) { 
        $('div.nicEdit-panelContain').css({ 'position': 'fixed', 'top':0, 'left':0 });
        } else {
        $('div.nicEdit-panelContain').css({ 'position': 'relative' }); 
    }
};
sticky_panelContainer();
$(window).scroll(function() {
    sticky_panelContainer();
});

But you must edit nicedit.js, because the buttontips and pulldowns will not work right. The topoffset start must be the panel top. Open nicedit.js and search the "pos : function()", it is near the beginning. And change

var curleft = curtop = 0; 

in

var curleft = curtop = 0;
if ($('div.nicEdit-panelContain').css('position') == 'fixed') {
    curtop = $('div.nicEdit-panelContain').offset().top;
}

jsfiddle example



来源:https://stackoverflow.com/questions/34571418/how-to-sticky-nicedit-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!