Search code examples
javascriptjquerybxslider

bxslider move first slide


How to make first bxslider slide to move -26px to left? I find out this line in slider:

propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)';

so I could change 'translate3d(' + value + 'px, 0, 0)' to 'translate3d(' + (value - 26) + 'px, 0, 0)'

and it would work, but the problem is, that I'm using several slides with different params and I can't modify this script. So how make it to move first slide by -26px to left?


Solution

  • i tried a little bit and try it and let me know and

    when you initialize, do like below

      $('.home .bxslider').bxSlider({
        initLeftVal: 20
      });
    
    
        //first, add extra property to defautls
        var defaults = {
            initLeftVal: 0;
        }
    
        //check for this function and replace whole function( dont replace just comment out)
        var setSlidePosition = function(){
            var initLeftVal = slider.settings.initLeftVal;
            // if last slide, not infinite loop, and number of children is larger than specified maxSlides
            if(slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop){
                if (slider.settings.mode == 'horizontal'){
                    // get the last child's position
                    var lastChild = slider.children.last();
                    var position = lastChild.position();
                    // set the left position
                    setPositionProperty(-(position.left + initLeftVal - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0);
                }else if(slider.settings.mode == 'vertical'){
                    // get the last showing index's position
                    var lastShowingIndex = slider.children.length - slider.settings.minSlides;
                    var position = slider.children.eq(lastShowingIndex).position();
                    // set the top position
                    setPositionProperty(-(position.top+initLeftVal), 'reset', 0);
                }
            // if not last slide
            }else{
                // get the position of the first showing slide
                var position = slider.children.eq(slider.active.index * getMoveBy()).position();
                // check for last slide
                if (slider.active.index == getPagerQty() - 1) slider.active.last = true;
                // set the repective position
                if (position != undefined){
                    if (slider.settings.mode == 'horizontal') setPositionProperty(-(position.left+initLeftVal), 'reset', 0);
                    else if (slider.settings.mode == 'vertical') setPositionProperty(-(position.top+initLeftVal), 'reset', 0);
                }
            }
        }