【DIY】可拖拽侧边栏

lanran 2021-8-12 1092

有时候星标里一行文字太多导致折行,感觉折行看着怪怪的,于是就有了这玩意。。。

效果(防止误导放原皮肤的效果吧......)

代码(见附件)

上传的附件:
快速回复
最新回复 (5)
  • sheen 2021-8-12
    1 2
    pluginManager.register('dragLeftSideBar',{
        run(){
            $('#leftsidebar')
                .on('mouseover mousedown',function(e){
                    const client_x = e.clientX,
                        trigger_width = 10,
                        min_width = 250,
                        $leftsidebar = $(this),
                        width = $leftsidebar.width(),
                        is = {
                            mouseover:e.type === 'mouseover',
                            mousedown:e.type === 'mousedown',
                            movePosition: client_x >= width - trigger_width 
                        }
    
                        if(is.movePosition){
                            is.mouseover
                                && $leftsidebar
                                    .style('border-right',`${trigger_width}px solid #eee`)
    
                            is.mousedown
                                && $(window)
                                        .on('mousemove',function(e){
                                            const x = e.pageX,
                                                max_width = $(this).width() * 0.25,
                                                width = $leftsidebar.width();
                                            if(x >= width && x <= max_width){
                                                $leftsidebar
                                                    .style('width',x)
                                            }
                                            if(x <= min_width ){
                                                $leftsidebar
                                                    .style('width','')
                                            }
                                        })
                                        .on('mouseup',function(){
                                            $(this).off('mousemove')
                                            $leftsidebar
                                                .style('border-right','')
                                        })
                        }
                })
    
            $(document.body)
                .append(`
                    <style>
                        #jShape.ls-toggle-menu #leftsidebar {
                            margin-left: 0px !important;
                        }
                    </style>
                `)
    
            plugin
                .systabs
                .tabs['ls-toggle-btn']
                .action = function({$tab}){
                    $(document.body)
                        .toggleClass("ls-toggle-menu")
                    $tab.removeClass("active")
    
                    let ishiddenLeftSidebar = $(document.body).attr('class').includes('ls-toggle-menu')
                        $windowWidth = $(window).width(),
                        $leftSidebar = $('#leftsidebar'),
                        $leftSidebarWidth = $leftSidebar.width()
                        
                    if(ishiddenLeftSidebar || $windowWidth < 1280){
                        $leftSidebar
                            .css('transform',`translateX(-${$leftSidebarWidth}px)`)
                    }else{
                        $leftSidebar
                            .css('transform',`translateX(0)`)
                    }
                    
                }
        }
    })
    .run()

     

    帮楼主把代码贴出来,谢谢楼主分享

  • lanran 2021-8-12
    0 3
    max_width 是 能拖拽的 最大宽度,默认是 浏览器宽度的 25%(0.25) ,想改大点 可以 手动改下 这个常量的值 emm 不推荐改太大了,太大了 会把 中间的内容挡住。。。
  • lanran 2021-8-12
    0 4
    sheen pluginManager.register('dragLeftSideBar',{ run(){ $('#leftsidebar') .on(' ...
    谢谢,我很早之前贴代码的时候 代码没发出来,于是这次就整成文件了。。。
  • 加佳 2021-8-12
    0 5
    这是css么
  • lanran 2021-8-12
    0 6
    加佳 这是css么
    js + css
返回