Tips and Tricks: carouFredSel: Unterschied zwischen den Versionen

Aus CodeCoupler Wiki
Zur Navigation springen Zur Suche springen
Tm (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Tm (Diskussion | Beiträge)
Zeile 65: Zeile 65:
     $('#slideshow').carouFredSel({
     $('#slideshow').carouFredSel({
swipe:{
swipe:{
    onTouch: true,
    onTouch: true
}
}
     });
     });
Zeile 72: Zeile 72:


You can additionaly enable sliding by dragging with the mouse:
You can additionaly enable sliding by dragging with the mouse:


<pre>
<pre>
Zeile 82: Zeile 81:
}
}
     });
     });
})
</pre>
== Add Previous / Next Buttons ==
=== Free Positioning ===
Add somewhere two div's for the next and the previous button. We use here the builtin icons of Bootstrap.
<pre>
<div id="slideshow">
  <img src="assets/img/1.jpg" width="663" height="491">
  <img src="assets/img/2.jpg" width="663" height="491">
  <img src="assets/img/3.jpg" width="663" height="491">
  <img src="assets/img/4.jpg" width="663" height="491">
</div>
<div id="slideshow_next"><span class="glyphicon glyphicon-chevron-right"></span></div>
<div id="slideshow_prev"><span class="glyphicon glyphicon-chevron-left"></span></div>
</pre>
Tell carouFredSel to use the buttons and not to start automatically. Additionally we enable the use of the keyboard keys "right" and "left":
<pre>
$(function(){
    $('#slideshow').carouFredSel({
auto: false,
prev:{
    button:'#slideshow_prev',
    key: 'left'
},
next:{
    button:'#slideshow_next',
    key:'right'
},
swipe:{
    onTouch: true
}
    });
})
</pre>
=== Positioning inside the Slideshow ===
You have to wrap your slideshow and your buttons into a wrapping div. We use here the builtin icons of Bootstrap.
<pre>
<div id="slideshow_wrapper">
  <div id="slideshow">
      <img src="assets/img/1.jpg" width="663" height="491">
      <img src="assets/img/2.jpg" width="663" height="491">
      <img src="assets/img/3.jpg" width="663" height="491">
      <img src="assets/img/4.jpg" width="663" height="491">
  </div>
  <div id="slideshow_next"><span class="glyphicon glyphicon-chevron-right"></span></div>
  <div id="slideshow_prev"><span class="glyphicon glyphicon-chevron-left"></span></div>
</div>
</pre>
Mixing the wrapper with the Bootstrap grid system is no problem:
<pre>
<div class="col-xs-8" id="slideshow_wrapper">
</pre>
Now positioning and style the buttons with css:
<pre>
#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}
</pre>
Use the same JavaScript as above:
<pre>
$(function(){
    $('#slideshow').carouFredSel({
auto: false,
prev:{
    button:'#slideshow_prev',
    key: 'left'
},
next:{
    button:'#slideshow_next',
    key:'right'
},
swipe:{
    onTouch: true
}
    });
})
</pre>
=== Show the Buttons only on Mouse-Over ===
There are two mthods doing this.
==== Simply CSS Method ====
The first and simply one is to add two additionally lines into your css:
<pre>
#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}
#slideshow_wrapper:hover #slideshow_next,
#slideshow_wrapper:hover #slideshow_prev {display: block !important;}
</pre>
And two additinally lines into your JavaScript:
<pre>
$(function(){
    $('#slideshow').carouFredSel({
auto: false,
prev:{
    button:'#slideshow_prev',
    key: 'left'
},
next:{
    button:'#slideshow_next',
    key:'right'
},
swipe:{
    onTouch: true
}
    });
    $('#slideshow_prev').hide();
    $('#slideshow_next').hide();
})
</pre>
This is because carouFredSel will always set "display:block" as element style of the buttons.
==== Fade In and Out ====
If you want fading the bvuttons, you do not have to add nothing to your css:
<pre>
#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}
</pre>
But add some more code into your JavaScript:
<pre>
$(function(){
    $('#slideshow').carouFredSel({
auto: false,
prev:{
    button:'#slideshow_prev',
    key: 'left'
},
next:{
    button:'#slideshow_next',
    key:'right'
},
swipe:{
    onTouch: true
}
    });
    $('#slideshow_prev').hide();
    $('#slideshow_next').hide();
    $('#slideshow_wrapper').hover(function(){
$('#slideshow_prev').fadeIn();
$('#slideshow_next').fadeIn();
    },function(){
$('#slideshow_prev').fadeOut();
$('#slideshow_next').fadeOut();
    })
})
})
</pre>
</pre>

Version vom 2. März 2014, 15:50 Uhr

Some Basics

Using with Bootstrap Grids

Do not convert a Bootstrap Grid-Div into a CarouFredSel-Slider:

<!-- WILL NOT WORK ! -->
<div class="col-xs-8" id="slideshow">
   <img src="assets/img/1.jpg" width="663" height="491">
   <img src="assets/img/2.jpg" width="663" height="491">
   <img src="assets/img/3.jpg" width="663" height="491">
   <img src="assets/img/4.jpg" width="663" height="491">
</div>

This will break the Grid Layout. Use instead an own Div for the Slideshow:

<div class="col-xs-8">
   <div id="slideshow">
      <img src="assets/img/1.jpg" width="663" height="491">
      <img src="assets/img/2.jpg" width="663" height="491">
      <img src="assets/img/3.jpg" width="663" height="491">
      <img src="assets/img/4.jpg" width="663" height="491">
   </div>
</div>

Simple Slider

HTML:

<div id="slideshow">
   <img src="assets/img/1.jpg" width="663" height="491">
   <img src="assets/img/2.jpg" width="663" height="491">
   <img src="assets/img/3.jpg" width="663" height="491">
   <img src="assets/img/4.jpg" width="663" height="491">
</div>

JS:

$(function(){
   $('#slideshow').carouFredSel();
})

Enabling Swiping

You have to enable swiping-support in the component configuration (it's enabled by default):

$config['master_components']['gui-libraries.sliders.carouFredSel']['config'] = array(
    'swiping' => TRUE
);

Then you have to add the following to your JavaScript:

$(function(){
    $('#slideshow').carouFredSel({
	swipe:{
	    onTouch: true
	}
    });
})

You can additionaly enable sliding by dragging with the mouse:

$(function(){
    $('#slideshow').carouFredSel({
	swipe:{
	    onTouch: true,
	    onMouse: true
	}
    });
})

Add Previous / Next Buttons

Free Positioning

Add somewhere two div's for the next and the previous button. We use here the builtin icons of Bootstrap.

<div id="slideshow">
   <img src="assets/img/1.jpg" width="663" height="491">
   <img src="assets/img/2.jpg" width="663" height="491">
   <img src="assets/img/3.jpg" width="663" height="491">
   <img src="assets/img/4.jpg" width="663" height="491">
</div>
<div id="slideshow_next"><span class="glyphicon glyphicon-chevron-right"></span></div>
<div id="slideshow_prev"><span class="glyphicon glyphicon-chevron-left"></span></div>

Tell carouFredSel to use the buttons and not to start automatically. Additionally we enable the use of the keyboard keys "right" and "left":

$(function(){
    $('#slideshow').carouFredSel({
	auto: false,
	prev:{
	    button:'#slideshow_prev',
	    key: 'left'
	},
	next:{
	    button:'#slideshow_next',
	    key:'right'
	},
	swipe:{
	    onTouch: true
	}
    });
})

Positioning inside the Slideshow

You have to wrap your slideshow and your buttons into a wrapping div. We use here the builtin icons of Bootstrap.

<div id="slideshow_wrapper">
   <div id="slideshow">
      <img src="assets/img/1.jpg" width="663" height="491">
      <img src="assets/img/2.jpg" width="663" height="491">
      <img src="assets/img/3.jpg" width="663" height="491">
      <img src="assets/img/4.jpg" width="663" height="491">
   </div>
   <div id="slideshow_next"><span class="glyphicon glyphicon-chevron-right"></span></div>
   <div id="slideshow_prev"><span class="glyphicon glyphicon-chevron-left"></span></div>
</div>

Mixing the wrapper with the Bootstrap grid system is no problem:

<div class="col-xs-8" id="slideshow_wrapper">

Now positioning and style the buttons with css:

#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}

Use the same JavaScript as above:

$(function(){
    $('#slideshow').carouFredSel({
	auto: false,
	prev:{
	    button:'#slideshow_prev',
	    key: 'left'
	},
	next:{
	    button:'#slideshow_next',
	    key:'right'
	},
	swipe:{
	    onTouch: true
	}
    });
})

Show the Buttons only on Mouse-Over

There are two mthods doing this.

Simply CSS Method

The first and simply one is to add two additionally lines into your css:

#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}
#slideshow_wrapper:hover #slideshow_next,
#slideshow_wrapper:hover #slideshow_prev {display: block !important;}

And two additinally lines into your JavaScript:

$(function(){
    $('#slideshow').carouFredSel({
	auto: false,
	prev:{
	    button:'#slideshow_prev',
	    key: 'left'
	},
	next:{
	    button:'#slideshow_next',
	    key:'right'
	},
	swipe:{
	    onTouch: true
	}
    });
    $('#slideshow_prev').hide();
    $('#slideshow_next').hide();
})

This is because carouFredSel will always set "display:block" as element style of the buttons.

Fade In and Out

If you want fading the bvuttons, you do not have to add nothing to your css:

#slideshow_next {cursor:pointer; position:absolute; top:230px; color:white; font-size:31px;}
#slideshow_prev {cursor:pointer; position:absolute; top:230px; right:5px; color:white; font-size:31px;}

But add some more code into your JavaScript:

$(function(){
    $('#slideshow').carouFredSel({
	auto: false,
	prev:{
	    button:'#slideshow_prev',
	    key: 'left'
	},
	next:{
	    button:'#slideshow_next',
	    key:'right'
	},
	swipe:{
	    onTouch: true
	}
    });
    $('#slideshow_prev').hide();
    $('#slideshow_next').hide();
    $('#slideshow_wrapper').hover(function(){
	$('#slideshow_prev').fadeIn();
	$('#slideshow_next').fadeIn();
    },function(){
	$('#slideshow_prev').fadeOut();
	$('#slideshow_next').fadeOut();
    })
})