How to fix scrollX movement issue in jQuery DataTables on mobile devices?

前端 未结 1 569
你的背包
你的背包 2021-01-18 11:01

I have used below code to simulate fixed header with vertical and horizontal scroll bars. See example on jsFiddle.

$(\'#liveTable\').dataTable({
      \'bSor         


        
相关标签:
1条回答
  • 2021-01-18 11:35

    Try this if it works for you. It's the other way around, but it works. Maybe you'll just need to adjust width or whatsoever. Run it through jsFiddle to test it.

    $.event.special.scrollstart = {
            enabled: true,
    
                setup: function() {
                    var thisObject = this,
                        $this = $( thisObject ),
                            scrolling,
                            timer;
    
                    function trigger( event, state ) {
                        scrolling = state;
                        var originalType = event.type;
                        event.type = scrolling ? "scrollstart" : "scrollstop";
                        $.event.handle.call( thisObject, event );
                        event.type = originalType;
                    }
    
    
                    $this.bind( scrollEvent, function( event ) {
                        if ( !$.event.special.scrollstart.enabled ) {
                            return;
                        }
    
                        if ( !scrolling ) {
                            trigger( event, true );
                        }
    
                        clearTimeout( timer );
                        timer = setTimeout(function() {
                            trigger( event, false );
                        }, 50 );
                    });
                }
        };
    

    Ok, if the flickering effect exists, try something like this. Your scroll is ok. It's the effect that sucks.

                    document.getElementById("btn").addEventListener("click", function(){
                        var abc = document.getElementById("abc");
                        var def = document.getElementById("def");
    
                        abc.style["-webkit-transition-duration"] = "0ms";
                        def.style["-webkit-transition-duration"] = "0ms";
                        abc.style["-webkit-transform"] = "translate3d(0, 0, 0)";
                        def.style["-webkit-transform"] = "translate3d(100%, 0, 0)";
                        setTimeout(function(){
                            abc.style["-webkit-transition-duration"] = "1s";
                            def.style["-webkit-transition-duration"] = "1s";
                            abc.style["-webkit-transform"] = "translate3d(-100%, 0, 0)";
                            def.style["-webkit-transform"] = "translate3d(0, 0, 0)";
                        },
    );
                    }); 
    
    0 讨论(0)
提交回复
热议问题