Open code100 opened 7 years ago
Having the same problem here.
It would be great to break the controls out of the parent div for placement outside of the scroller
This can be achieved with a little extra code.
var slider = $('.lightslider-gallery').lightSlider({
...
controls: false,
...
});
<div class="my-carousel">
<div class="lSAction">
<a class="lSPrev"></a>
<a class="lSNext"></a>
</div>
<ul class="lightslider-gallery">
<li>
....
Note: by keeping the same class names, they will appear exactly as the default controls.
$('.lSAction > .lSPrev').click(function () {
slider.goToPrevSlide();
});
$('.lSAction > .lSNext').click(function () {
slider.goToNextSlide();
});
.lSAction > .lSPrev {
left: -100px;
}
.lSAction > .lSNext {
right: -100px;
}
Sorry, noob here... Where and how to add manualy click handling (3th point)?
$('.lSAction > .lSPrev').click(function () { slider.goToPrevSlide(); }); $('.lSAction > .lSNext').click(function () { slider.goToNextSlide(); });
@suroviec in the same JS file where you initialize the slider. Let's say you have your JS inline, something like this should be in your HTML:
<!-- jQuery included via CDN, but you can download and serve from your server -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<!-- LightSlider included via CDN, but you can download and serve from your server -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightslider/1.1.6/js/lightslider.min.js"></script>
<script type="text/javascript">
$(function() {
// Init lightslider
var slider = $('.lightslider-gallery').lightSlider({
...
controls: false,
...
});
// Manually add click handlers
$('.lSAction > .lSPrev').click(function () {
slider.goToPrevSlide();
});
$('.lSAction > .lSNext').click(function () {
slider.goToNextSlide();
});
}
</script>
Hope this helps!
Thank you very much! That works! I`m starting to learn JavaScript tommorow :)
Сorrect solution, in my opinion, is editing lightslider.js file:
replace it:
controls: function () {
if (settings.controls) {
$el.after('<div class="lSAction"><a class="lSPrev">' + settings.prevHtml + '</a><a class="lSNext">' + settings.nextHtml + '</a></div>');
if (!settings.autoWidth) {
if (length <= settings.item) {
$slide.find('.lSAction').hide();
}
} else {
if (refresh.calWidth(false) < elSize) {
$slide.find('.lSAction').hide();
}
}
$slide.find('.lSAction a').on('click', function (e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
if ($(this).attr('class') === 'lSPrev') {
$el.goToPrevSlide();
} else {
$el.goToNextSlide();
}
return false;
});
}
},
on its:
controls: function () {
if (settings.controls) {
$el.parents('.lSSlideOuter').append('<div class="lSAction"><a class="lSPrev">' + settings.prevHtml + '</a><a class="lSNext">' + settings.nextHtml + '</a></div>');
if (!settings.autoWidth) {
if (length <= settings.item) {
$slide.parents('.lSSlideOuter').find('.lSAction').hide();
}
} else {
if (refresh.calWidth(false) < elSize) {
$slide.parents('.lSSlideOuter').find('.lSAction').hide();
}
}
$slide.parents('.lSSlideOuter').find('.lSAction a').on('click', function (e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
if ($(this).attr('class') === 'lSPrev') {
$el.goToPrevSlide();
} else {
$el.goToNextSlide();
}
return false;
});
}
},
and add css:
.lSSlideOuter{
overflow: visible;
}
.lSSlideWrapper{
overflow: hidden;
}
.lSAction{
position: relative;
}
vladim you are the best!
By far the easiest solution is to move .lSAction container after slider load, like this:
$('.light-slider').lightSlider({
item: 3,
pager: false,
onSliderLoad: function (el) {
var parent = el.parent();
var action = parent.find('.lSAction');
action.insertBefore(parent);
}
});
After that, simply set .lSSlideOuter container to visible and position your left/right buttons in CSS:
.lSSlideOuter {
overflow: visible;
}
...
.lSAction > .lSPrev {
left: -32px;
top: 50px;
}
.lSAction > .lSNext {
right: -32px;
top: 50px;
}
No source code changing or anything complicated.
Simply we can override the Lightslider plugin CSS to :
.lSSlideOuter {
position: relative;
overflow: visible;
}
and override the position relative to static of .lSSlideWrapper.
.lSSlideWrapper {
position: static;
}
Hello friends, I'm noob, I'm trying to find the javascript file but I can't find it in my hosting files, I'm trying to index my website but google tells me to add href attribute in the links:
div.lSSlideOuter > div.lSSlideWrapper > div.lSAction > a.lSPrev
div.lSSlideOuter > div.lSSlideWrapper > div.lSAction > a.lSNext
I will appreciate someone who can help me please, good day. =)
I am trying to put prev/next button to be outside of the box, but they are not showing after I apply for following css.
This is due to position:relative in following css, I am not sure if position: relative is necessary or it could be removed.