[英]Bootstrap carousel: changing jquery slides to bootstrap caroulsel and binding a slide function
我開始在我的網站上應用引導程序。 我需要更改以下腳本以在引導輪播上工作
$(function(){
// Set starting slide to 1
var startSlide = 1;
// Get slide number if it exists
if (window.location.hash) {
alert('hash'+window.location.hash);
startSlide = window.location.hash.replace('#','');
alert('startslide'+startSlide);
}
// Initialize Slides
$('#slides2').slides({
preload: true,
preloadImage: 'img/loading.gif',
generatePagination: true,
play: 0,
pause: 2500,
hoverPause: true,
currentClass: 'current',
// Get the starting slide
start: {$startNumb},
animationComplete: function(current){
// Set the slide number as a hash
window.location.hash = '#' + current;
alert('windows hash'+window.location.hash);
alert('current'+current);
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
}
});
我已經嘗試過類似的方法,但是它不起作用。 我不知道current
變量在哪里獲取其值以及window.location.hash
如何工作
$(function(){
// Set starting slide to 1
var startSlide = 1;
// Get slide number if it exists
if (window.location.hash) {
startSlide = window.location.hash.replace('#','');
}
$('#myCarousel').bind('slide',function(current){
window.location.hash = '#' + current;
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
});
});
找到了解決方案。此解決方案獲取輪播的當前索引
$('#myCarousel').bind('slid',function(e){
var current = $(".active", e.target).index()+1;
$('#activeSlideIndex').val(current);
$('#popLightbox div.rating a').attr('rel', imageIdArray[current-1] +';media');
$('#popLightbox a.voteNegative').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/unlike.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][0]);
$('#popLightbox a.votePlus').html('<img src="{$liveSite}/templates/{$theme}/desktop_images/images/approve.png" align="absmiddle"><b class="sprite"> </b> ' + voteCountArray[current-1][1]);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.